Program rule expression

Hi everyone

In an event program is there a program rule expression to display the capture of a data élement in another field. ?

Hi @elmoujarrade,
May I ask you for the use case or an example please? It does sound like you’d be duplicating something? It is possible to assign another data element based on the value of another field, yes!

Thank you for your patience!

1 Like

Thank you for your reply.
I will give more detail about my problem: I have a program 1 and a program 2.
Program 1 contains fields A, B, and C
Program 2 contains fields D, E, and F
Now I want the data already entered in the A field, automatically appear in the D field. How should I proceed
thanks for your support

@elmoujarrade If you were wanting to, within a single event program, assign a value from one field to another, this is definitely possible (Program rule–>action = “Assign Value”). In your example above, if you had data in A, it could populate into C.

The limitation here though is that this action can only be pulled within a single event (i.e. the assign value won’t pull from a previous event and populate). This will prevent you pulling data from A and pushing into D, as you’ve noted that A and D are in different programs and thus won’t ever be in the same single event.


Yes, @elmoujarrade, as @Matthew_Boddie pointed it that it’s not possible to use between programs; however, it’s still possible to create a feature request to describe the use case and this is important for the community (so other community members add their vote) and if DHIS2 core team agree with the importance of this feature, they’ll add it to future versions. :+1: Thanks!

Thanks @Matthew_Boddie for your response too!


Thank you for your support
I want to do the test in the same program.
In this case, what is the program rule expression?

@elmoujarrade ok great! You can do it a number of ways. Let’s Assume you are assigning value of A into C. Some options:
Expression: true
This will basically always fire the action–Basically C will always be showing what is in A. Another outcome of this is that C will always be read-only–i.e. you can’t change the value (when the Assign Value action is fired, it prevents editing)

Expression: d2:hasValue(#{A})
This will fire if and only if there exists a value in Data Element A. This is sometimes convenient, and commonly paired with another program rule to hide Data Element C until A as a value. The combination of these two Prules will remove visibility of C until it is relevant and has a value from A to be assigned to.

Expression: d2:hasValue(#{A}) && !(d2:hasValue(#{C}))
This will fire once, assigning the value of A, but then will immediately remove the read-only aspect of C (because the action will put in a value in C, thus making the expression false). This is useful if you’d like to have a “default” response but want to allow for the response to be edited. Keep in mind that if someone removed the default response altogether, it would bring it back and could be frustrating for a user.

Do all of these make sense?


I want to use the first case (Expression: true), could you write me the exact expression I need to put in the “Enter program rule expression” section, then
in “Define program rule actions”.
thank you very much for your help

@elmoujarrade displays what I’ve done for Smoking and smoking cessation DEs. is the Prule itself


Here’s a quick GIF on how that presents itself in the Capture App:
Assign Value

1 Like

Hi, @Matthew_Boddie
Thanks for the support
it works very well, I did a test in the PLAY instance for the Gender “A” and Gender test “C” fields.