Range expression not working in program rule

In my case, I have configured an integer type data element and a program rule to check the range entered by user between 1-87, but the program rule is not working.

Thanks


@rithvik,

1 Like

Hi @hernandezmachava

It seems the range in the expression is not defined to be the numbers between 1-87. It should be greater than zero and less than or equal to 87, but it shows less than or equal to zero and greater than 87 (impossible!)

Here’s the fix, and I hope it works:

Hi @Gassim,

I have corrected the PR expression, but it is still not working.

Here is the program rule variable

Thanks

Hi @hernandezmachava

Sorry for taking this long! Just to make sure it’s not the expression, could you try to change it without d2:hasValue?
(#{Padroes avaliados}) && (#{Padroes avaliados} > 0 && #{Padroes avaliados} <= 87)

Thanks!

Hi @Gassim,
I removed d2:hasValuebut it is showing an error:

I have also tried in Demo, but the expression is not working

Thanks

Hi @hernandezmachava

I have looked at your issue and testing it my self, until I made it work. You need to change your expression back to how it originally was.
And you need to use ‘OR’ instead of ‘AND’ when checking the range.

So your expression will look like this: d2:hasValue:(#{Padroes avaliados}) && (#{Padroes avaliados} <= 0 || #{Padroes avaliados} > 87)

So now the expression says that the data element must have a value, and if the DE has value <= 0 OR > 87 the program rule will trigger.

I dont know the action in your program rule, but I sat up to show an error. So if enter 89 or -1 it will show an error.

Caroline

2 Likes

Hi @Caroline,

I have changed the expression, but it is not working:

No error is shown if I enter a number that is outside the range:

Thanks

Sorry I meant:
(#{Padroes avaliados} != ‘’) && (#{Padroes avaliados} > 0 && #{Padroes avaliados} <= 87)

@hernandezmachava

Strange… What version of Dhis2 are you running?

Caroline

1 Like