D2:condition() in 2.31 Program Rule Error Message

Put this in a Program Rule Action Expression:
d2:condition(‘d2:left(V{orgunit_code},3) == ‘ZA-’’,‘Zambia’,‘Not Zambia’)

The Program Rule itself seems to be working, because the Show error action still fires. the expression itself meant to display after the static text is not functional. Within the console, I find:

angular.js:11655 Expression with id action:NNAPsbz2uzz could not be run. Original condition was: d2:condition(‘d2:left(V{orgunit_code},3) == ‘ZA-’’,‘Kenya’,‘Not Kenya’) - Evaluation ended up as:d2:condition(‘d2:left(‘ZA-Bulaya Village’,3) == ‘ZA-’’,‘Kenya’,‘Not Kenya’) - error message:SyntaxError: missing ) after argument list

Trying to figure out why my formula is mal-formatted; looks like ’ ’ is necessary and noted to be required in dhis-2 documentation; removing the ‘’ for the true and false parameters does not fix the solution. I’m wondering if it might be the () within the d2:left formula which is causing the entire thing to break. This sounds similar to [DHIS2-2813] - Jira, and while it notes being fixed in 2.29, it also notes tracker, so not sure if the fact that I’m in Event Capture (2.31.6) is important.

Thanks for any assistance!

1 Like

Hi @Matthew_Boddie,

Thanks for raising this issue, tagging @Markus to have a look to figure out whether it’s the formatting or what is the issue.

Best regards,
Karoline

1 Like

Hi there @Matthew_Boddie,
This could perhaps be build with a bit less nesting? If you make a program rule where the condition is
d2:left(V{orgunit_code},3) == 'ZA-'
And a program rule action that assigns/shows “Zambia”.

And make a twin rule that has the condition:
d2:left(V{orgunit_code},3) != 'ZA-'
And then assigns shows “Not Zambia”?

Best regards,
Markus

1 Like

Thanks for the response. That makes sense; we are trying to translate all of our program rule messages for each of our programs, and so I’m wary of the multiplicative affect here for 4 languages and hundreds of program rules. That said, we could probably get creative in other ways of chunking the messages to limit down the iterations. I’ll work a bit on this and come back with any progress. Thanks again!

1 Like