In the picture below, I would like the following validation A_ST1 + A_ST2 = A_ST. What I mean is: as the value of A_ST is 30 and the value of A_ST1 is 12, the value of A_ST2 should 18 (i.e if the user enters a value less than or greater than 18, a message should displayed to tell the user to enter a correct value).
The program rules variables are assigned to the same DE that you used and the source type is Data element in current event
As program rule action you can select the Show error action and in the expression to evaluate use the same function used for the Program rule
#{A_ST}-#{A_ST1}
In this way if the value entered in the DE A_ST2 is different from the difference between A_ST and A_ST1 the Program Rule will return you a message with the correct value to insert
In the Program Rule Action you can chose other outputs if necessary
I have tested the program rule and it works. But I have two more questions:
My team has said that the data entry clerk may choose to fill A_ST2 first instead of A_ST1. In this case do I have to create another program rule like d2:hasValue(#{A_ST1})&& #{A_ST1}!=#{A_ST}-#{A_ST2}?
2- In the source type for the program variable, we have other options Data element for the newest event for a program stage Data element from the newest event in the current program
When do we use them so that I can be confident which one to choose in other scenarios?
in case they could choose to fill A_ST2 instead of A_ST1 and there is no a sequential order in the data entry I’ll then suggest to change the program rule to the following one
There is no sequential order in the data entry. I have another program stage with 12 fields, but I got the idea. I will have to combine all (12) of them in the program rule as in your example below.