Table method ModifiedFieldValue() in D365 F&O - X++ Code

X++ Programming Language >   D365 Table >   Table Methods  

Long Question

4202


Answer:

ModifiedFieldValue method Modifies the specified field to the original value. ModifiedFieldValue method takes field name and array index as arguments

Syntax


public void modifiedFieldValue(FieldName _fieldName, int _arrayIndex = 1)
{
    super(_fieldName, _arrayIndex); 
}
Parameters:
  1. _fieldName: The array index of the field; optional.(String)
  2. _arrayIndex: The array index of the field; optional. (Int32)

The modifiedFieldValue method in Microsoft Dynamics 365 for Finance and Operations (D365FO) is typically used to react to changes in field values within the application's user interface (UI). This method is often overridden or extended in customizations and extensions to add specific business logic or validation when certain fields are modified by users. Here's why it is used:

  1. Field Change Detection: The primary purpose of the modifiedFieldValue method is to detect when a specific field's value has been modified. This allows you to trigger actions or validation based on these changes.

  2. Business Logic: When certain fields change, your business processes may require additional actions or calculations. For example, if the user changes an account type from "Current" to "Savings," you may need to adjust minimum balance requirements or apply specific rules.

  3. Validation: You can use this method to perform validation checks when fields are modified. For instance, you might want to ensure that a discount percentage field remains within a certain range when a related price field changes.

  4. Customization: D365FO is often customized to meet specific business requirements. By overriding the modifiedFieldValue method, you can inject custom logic into the standard application behavior without modifying the core system code.

  5. Event Handling: This method is commonly used as an event handler for field changes. When a field is modified, the method is automatically called, allowing you to respond to the change without relying on manual user actions.


Example



public void modifiedFieldValue(FieldName _fieldName, int _arrayIndex = 1)
{
    super(_fieldName, _arrayIndex);

    if(_fieldName == fieldStr(HD_BankCustomersTable, AccountType))
    {
        switch(this.AccountType)
        {
            case HD_AccountType::Current:
                this.MinBalance = 5000;
                break;

            case HD_AccountType::Fixed:
                this.MinBalance = 10000;
                break;

            case HD_AccountType::Recurring:
                this.MinBalance = 500;
                break;

            case HD_AccountType::Savings:
                this.MinBalance = 1000;
                break;
        }
    }

}



Another Example


   /// <summary>
   ///
   /// </summary>
   /// <param name = "_fieldName"></param>
   /// <param name = "_arrayIndex"></param>
   public void modifiedFieldValue(FieldName _fieldName, int _arrayIndex = 1)
   {
       info(strFmt("%1", _fieldName));  // You will be able to see the FieldName like "Designation", "BasicSalary", etc.
       super(_fieldName, _arrayIndex);
 
       switch (_fieldName)
       {
           case fieldStr(EmployeeTable, Designation):
           if (this.Designation == AnsariDesignation::Engineer)
               {
                   this.BasicSalary = "10000";
               }
               if (this.Designation == AnsariDesignation::Doctor)
               {
                   this.BasicSalary = "12000";
               }
               break;
 
           // Add more cases for other fields and their corresponding logic as needed.
       }
   }



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.