Validation issues

Hi community,

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).

I welcome steps to achieve achieve this.

Thanks

Hi @hernandezmachava,

for your use case what I’ll suggest is to use a set of program rules

If I use the example that you report you can create a program rule for the Data Element A_ST2 and in the condition have the following:

d2:hasValue(#{A_ST2})
&&
#{A_ST2}!=#{A_ST}-#{A_ST1}

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

chrome-capture-2024-0-16

In the Program Rule Action you can chose other outputs if necessary

Let me know if not working

Hi @Stefano

I have tested the program rule and it works. But I have two more questions:

  1. 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?

Thanks again

Hi @hernandezmachava,

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

d2:hasValue(#{A_ST})
&&
d2:hasValue(#{A_ST1})
&&
d2:hasValue(#{A_ST2})
&&
#{A_ST}!=#{A_ST1}+#{A_ST2}

Then assign the program rule action to the DE A_ST and in the expression to show as error the following

#{A_ST1}+#{A_ST2}

In this case a message will be shown to the DE A_ST in case the sum of of the DEs A_ST1 + A_ST2 is different from A_ST

Is not that “clean” as the previous one but is the only solution that I can think of as either A_ST1 or A_ST2 can be filled first

chrome-capture-2024-0-18

Concerning your second question you can fidn the definition of the Program Rules source type here

Hi @Stefano,

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.

Thank you so much for your help. I was stuck