Program rule to specify that the Number must be> = 18

Dear all,

I create a tracker data element value type: Number

For event program, I want to use program to check and show error if Number is under 18
Can someone show me how to make a program rule to specify that the Number must be> = at 18.
I’m really appreciated if anyone has experience on this can share.

Regards,

Hi there,

In order to create the Program rule you must first create a “Program rule variable”.
From the “Maintenance” app, click on the “Program” menu and then select “Program rule variable”

Click on the + symbol and you will be able to create a variable that will hold the value of the data element you are referring to.
You will be asked to select which program it belongs to, a unique name for the variable, the source type, the program stage and then select the actual data element.

Click on “Save”, this has now created a variable for you to use in the “Program rule”.

So now click on the Program Rule menu item, click on the + to add a new rule.
The first section will be for selecting which Program and Stage the rule will be bound to and then entering the name, description and priority.

Select the link “2 Enter Program rule expression” at the top and this is where you will evaluate the variable you created in the very first step.
Your expression will look something like this → #{myVariable} <= 17

Now click on the link “3 Define program rule actions”.
Here you can specify any number of actions to take if your expression evaluates as true.

Hope this helps!

Peter

Hi, @Peter
Thanks for the support.
Your approach works well, except that the error message that I entered in link 3 of the program rule appears as soon as the form is opened, while what I want is for the error message to appear after the filling of the appropriate field.
Regards

Hi again,

You can modify your expression maybe to cater for a blank entry and make it something like #{myvariable} > 0 && #{myvariable} <= 17

I’m not sure if the value will default to 0 but then you could also use a function in your expression to see if the variable has a value

So it would be something like this
d2:hasValue(#{myvariable}) && #{myvariable} <= 17

Peter

1 Like

Hi, @Peter

it’s perfect, I tested the first proposal, and it works very well.
Thanks for helping me.

1 Like

Great, glad I could help.