Microsoft Dynamics 365 Blog

SummaryIf you have a page field that has a calculation as its SourceExpression and part of the calculation depends on another field, then the calculated field is not automatically recalculated when the other field is updated. The calculated field will first recalculate when the updated field’s OnValidate trigger is run, which  only runs if it contains code. So to enable the calculated field to recalculate automatically, you must put some code on the OnValidate trigger of the field that gets updated – even if it is only a comment line with no functionality.

Note: A page will only update a field if it detects that there is some code on the OnValidate trigger. This is done for performance reasons to avoid unnecessary updates.

Example

Let’s say you have the following two fields on a page:

Field1:
Name=Txt1;
SourceExpr=Txt1;

Field2:
Name=NewTxt1;
SourceExpr=Txt1 + ‘XYZ’

Field2 is supposed to add the text ‘XYZ’ to the value is entered in Field1. But when you enter a value in Field1, Field2 does NOT get automatically updated. To change this behaviour, add some C/AL code to the OnValidate trigger of Field1. For example, just add a simple comment like “//” or:

//This comment is used to update Field1 – do not delete

This will tell Field1 to run the OnValidation trigger, which in turn updates the other fields on the page.

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!