Table method modifiedField() in D365 F&O

X++ Programming Language >   D365 Table >   Table Methods  

Long Question

16651


Answer:

Each time the value of a field is changed the method modifiedField() is called. It is useful to initialize the values of other fields if the value of the current field is changed.

Example: Let’s now override modifiedField method for MyFirstTable and target is to set CurrencyCode to null when CustGroupId is modified.



public void modifiedField(fieldId _fieldId)
{
    switch(_fieldId)
    {
        case fieldnum(MyFirstTable, custGroupId):
            this.CurrencyCode="";
        break; 

        default:
            super(_fieldId);
    }
}


After adding this method, open table MyFirstTable using Table browser and try to modify custGroupId of an existing record, then you will notice that CurrencyCode is immediately set to blank.

ModifiedField() receives the field number of the active field as parameter. A switch statement is used to check which field is active. If none of the checked fields are active the super() call is executed instead.


Another Example

Table Methods - modifiedField
Figure:


Table Methods - modifiedField
Figure:


Table Methods - modifiedField
Figure:


Table Methods - modifiedField
Figure:


 public class EmployeeTable extends common
{
    public void modifiedField(FieldId _fieldId){

        //info(strFmt("%1", _fieldId));  // you will be able to see the Id like 1, 2, 3

        super(_fieldId);

        switch(_fieldId){
                case fieldNum(EmployeeTable, Designation):
                    if(this.Designation == AnsariDesignation::Engineer){
                        this.BasicSalary = "10000";
                    }

                    if(this.Designation == AnsariDesignation::Doctor)
                    {
                        this.BasicSalary = "12000";
                    }
                break;
        }
    
    }

}


This Particular section is dedicated to Question & Answer only. If you want learn more about X++ Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.