✏️ Explanatory Question

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

👁 9,979 Views
📘 Detailed Answer
💡

Answer with Explanation

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.


Table method validateField() in D365 F&O - X++ Code
Visual aid for: Table method validateField() in D365 F&O - X++ Code