I’m running into a confusing situation with the d2:lastEventDate function in program rule expressions and I’d like to confirm whether it’s a bug or whether I’m getting the syntax wrong.
When I use d2:lastEventDate in a program rule expression, the Maintenance app reports “Expression is not valid” as a warning, not an error. The rule itself appears to behave exactly as expected at runtime but the validation message shows up almost every time the expression contains d2:lastEventDate.
Additionally, it’s good to note that:
The warning has no description and just says the expression is not valid, with nothing explaining why, so I can’t tell whether it’s a genuine validation problem or a false positive.
This super useful function is missing from the expression builder and is not listed among the available functions in the rule expression builder UI, even though it is documented here: Programs - DHIS2 Documentation
Since the warning gives no detail, is this a known bug in the expression builder or is there a correct syntax for d2:lastEventDate that avoids the warning that I’m missing? Below is an example syntax that I’ve tested from version 2.41 to 2.43:
Thank you for your post! You’re right - this does feel a bit tricky!
I have some comments. I remember there were similar issues with other rules where the validation would show that they are invalid but during runtime/execution, they turn out to be working fine. The common reason in these situations is that for the validation to work it would require the value but when checking before runtime it can’t really get the ‘lastEventDate’ and returns null which makes it invalid.
You are right; however, it’s now available in the new app Metadata Management app, please have a look there:
Thanks for your response. The explanation on the common reason does makes sense to me; however, since the lastEventDate (almost?) always returns null in validation phase, it might be better to suppress confusing warning for this specific function. I’ve just created a JIRA ticket for it.
Regarding the new Metadata Management app, thanks for pointing it out, I see the function in the list.
Thank you @malekpour for creating the ticket. I see a response from @Karoline:
Hi @Mohammad-Reza Malekpour - you have to pass it as a string name (single-quoted variable name), not with the #{} syntax. This is in general in d2-functions. I’ll make sure to raise a docs PR to clarify this. (Important that it passes, as validation in the new Metadata Management app is stricter.)