Table method validateField() in D365 F&O - X++ Code
Answer:
Method validateField() is used for validation only and will return true or false. If the return value is false, the application user will be prevented to continue changing a field value.
Exampl: Let’s override validateField for MyFirstTable to verify the condition that CustName must be have > 3 characters.
public boolean validateField(fieldId _fieldIdToCheck) { boolean ret; ret = super(_fieldIdToCheck); if (ret) { switch (_fieldIdToCheck) { case fieldnum(MyFirstTable, custName): if (strlen(this.custName) <= 3) ret = checkFailed("Customer name must be longer than 3 characters."); } } return ret; }
After adding this method, open table MyFirstTable using Table browser and press Ctrl+N, in the new record try to enter less than 3 characters for field custName, Ax will throw warning message stating "Customer name must be longer than 3 characters." And you will be asked to enter value again. Thus we validate the data to be entered for a specific field.

Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of X++ Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.