Table method ModifiedFieldValue() in D365 F&O - X++ Code
X++ Programming Language > D365 Table > Table Methods
4654
Answer:
ModifiedFieldValue method Modifies the specified field to the original value. ModifiedFieldValue method takes field name and array index as arguments
Syntax
Parameters:public void modifiedFieldValue(FieldName _fieldName, int _arrayIndex = 1) { super(_fieldName, _arrayIndex); }
- _fieldName: The array index of the field; optional.(String)
- _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:
-
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. -
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.
-
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.
-
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. -
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
/// /// /// /// /// 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.