Program Rule expression not evaluating


Hi Markus,

Thank you for your response. Yes, I have checked a few times to make sure we have the right number of parentheses!

The values not getting populated are the two expressions: #{f6a_pr_edd_final} and #{f6a_pr_as_sfh}.

#{f6a_pr_edd_final} variable is linked to a few data elements.

  • We have a variable for #{f6a_pr_lmp}, which is linked to one data element. This is a DATE type field populated by the user. Once the user populates that field, we assign the value of that variable to the first variable #{f6a_pr_edd_lmp_sfh}.

  • Then we have another variable #{f6a_pr_ultrasound1_edd_date} which is linked to a data element that is a DATE type field for user to populate.Once the user populates the field, we assign the value to a second variable #{f6a_pr_edd_ultrasound}.

  • We are using priority to have the rules run in the desired order. After the above two variables get assigned, the value of the variable #{f6a_pr_edd_lmp_sfh} is then assigned to #{f6a_pr_edd_final} with priority #6 and #{f6a_pr_edd_ultrasound} is assigned to #{f6a_pr_edd_final} with priority #7.

Before checking if #{f6a_pr_edd_final} shouldn’t get triggered if it doesn’t have values, we are already doing several checks if the other variables do not have values.
I’m including a screenshot in case it’s easier to visualize.


#{f6a_pr_as_sfh} variable is linked to one data element that is a number type and nothing else. This variable is filled in when the user populates the field.

When I tested again this morning, I was still getting the same warning and two PUT errors for two data elements in the console. However, when I “Clear Cache,” the warning message and one PUT error disappeared. Then when I “Clear Cache” the second time, all warning and error messages disappeared.

Thank you.


1 Like


Thank you for the details. It still looks as if the original problematic expression:

(40-d2:weeksBetween(V{event_date},#{f6a_pr_edd_final}))>=16 && (40-d2:weeksBetween(V{event_date},#{f6a_pr_edd_final}))<=36 && ((40-d2:weeksBetween(V{event_date},#{f6a_pr_edd_final}))-#{f6a_pr_as_sfh})<=2

Does not itself check wether the necessary variable #{f6a_pr_edd_final} has a value. I would try to add

d2:hasValue('f6a_pr_edd_final') &&

in front of the whole expression.

You said that a cache clean works - does the original errors and warnings come back if you test starting with a new record? In the console it will by default only show you failing rules, and if the rule fails once, then starts working, the console will contain the warning from the time the rule failed.

Pro tip - To get output from all rules, failing and successful alike, add “&verbose” url of your tracker capture, using enter to refresh the page - then continue testing. This might help uncover when rules fails once or twice because of missing data, then starts working.

1 Like

Hi Markus,

Thank you for the pro tip! :smiley: I can see the expression being evaluated now.

I split the expression and tested each one to see which one is giving a false answer. The expression

((40-d2:weeksBetween(V{event_date},#{f6a_pr_edd_final}))-#{f6a_pr_as_sfh}) <=2

is returning a FALSE. However, I’m expecting to see a TRUE getting evaluated. I have a feeling I’m missing something here…


Hey again!
Looking at the expression being evaluated, the rule engine says that this is false:
((40-d2:weeksBetween(‘2018-11-01’,‘2018-11-07’) )-2) <= 2
When replacing the weeksbetween call with 1:
((40-1)-2) <= 2
boiling further down this ends up as:
37 <= 2
…which truly is false.

I guess there might be a logical error in the expression here if it was expected to be true?


Hi @Markus,

Thank you for your help!
We tested again and seems to be working now.