Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Initialize a field value when another field has changed

(1) ShareShare
ReportReport
Posted on by 40

Hai I am trainee technical consultant. This is the task given to me . I tried my best to create the table, but I am unable to meet the requirement asked in Cubical master table>FloorDescription> DataType to achieve the description value from the floor master table.

I tried it by using Modifiedfield method but I am not able to get succeeded please help me in this aspect.

thanks in advance.

 

Floor master:

S.No Field Name Label Mandatory DataType Size
1 FloorId Floor Id Yes String 10
2 Description Description No String 60

Cubicle master:

S.No Field Name Label Mandatory DataType Size
1 CubicleId Cubicle Id Yes String 10
2 Description Description No String 60
3 FloorId

Floor Id

Yes String 10
4 FloorDescription Floor Description No

Non-Editable.

Default FloorID Description

From Floor master

-

 

  • AxAspirant Profile Picture
    40 on at
    RE: Initialize a field value when another field has changed

    I got it as needed. Thanks for u help and time on investing to help me @Martin Dráb

  • Verified answer
    Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: Initialize a field value when another field has changed

    Please use Insert > Insert Code (switch to rich formatting to view this option) to paste source code. It uses single line spacing, provides line numbering, make code easier to copy and so on. This is the result:

    public void modifiedField(FieldId _fieldId)
    {
       FloorMaster floorMaster;
       
       super(_fieldId);
       
       switch(_fieldId)
       {
    	   case fieldNum(CubicalMaster,FloorId):
    		   this.FloorDescription = floorMaster.Description;
    		   break;
    	   default:
    		   break;
       }
    }

    If you debugged your code, you would have found that this.FloorDescription is empty because you assign an empty value to it. (As you see, the debugger can give you a lot of important information - make sure you use it.)

    The reason is in the fact that you never assigned anything to floorMater variable, therefore it has all fields empty. What you need to do is finding the FloorMaster record for the given FloorId. For example:

    public void modifiedField(FieldId _fieldId)
    {
    	super(_fieldId);
    
    	switch(_fieldId)
    	{
    		case fieldNum(CubicalMaster, FloorId):
    			FloorMaster floorMaster = FloorMaster::find(this.FloorId);
    			this.FloorDescription = floorMaster.Description;
    			break;
    	}
    }

    If FloorMaster doesn't have find() method, go and add it. You can find a plenty of examples in existing tables, but if you struggle with it anyway, feel free to ask.

    public void modifiedField(FieldId _fieldId)
    {
        FloorMaster floorMaster;
    
    	super(_fieldId);
    
    	switch(_fieldId)
    	{
    		case fieldNum(CubicalMaster, FloorId):
    			floorMaster = FloorMaster::find(this.FloorId);
    			this.FloorDescription = floorMaster.Description;
    			break;
    	}
    }

  • AxAspirant Profile Picture
    40 on at
    RE: Initialize a field value when another field has changed

    Yes I need to copy Description from floor master table to FloorDescription in Cubicle master.

    This is the code that I worked on it but its not copying the values as required.

    Code:

    public void modifiedField(FieldId _fieldId)

       {

           FloorMaster floorMaster;

           super(_fieldId);

           switch(_fieldId)

           {

               case fieldNum(CubicalMaster,FloorId):

                   this.FloorDescription = floorMaster.Description;

                   break;

               default:

                   break;        

           }

       }

  • Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: Initialize a field value when another field gets changed

    Title changed from "Help me in creating the below said tables as per the requirement." to "Initialize a field value when another field has changed".

  • Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: Help me in creating the below said tables as per the requirement.

    Does it mean that you want to copy Decription from Floor master table? I wonder if it's good design, but I guess it's not up to you at the moment. If you want to do it immediately when FloorId changes, modifiedField() is the right method. But I can't comment on your problem there, because you neither showed your code nor explained what problem you have with it.

    By the way, let me changed the thread category from "Other" to "Development / Customization / SDK" and try to set a more descriptive title.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,933 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,801 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans