Program rule works for non mandatory fields but not for mandatory fields

Hi, everyone.

DHIS 2 version 2.34.4

I am unable to hide a mandatory field in event capture through a program rule.
Tem iluminacao adequada na Maternidade is a mandatory yes/no DE.
Problema da falta de iluminacao adequada na Maternidade is a text valute type DE to be hidden - it is also mandatory

Program rule expression ------ I mean if the DE is empty or it is yes

!d2:hasValue( #{GS - Tem iluminacao adequada na Maternidade} ) || #{GS - Tem iluminacao adequada na Maternidade} == true

Program action

Hide field: “Problema da falta de iluminacao adequada na Maternidade”

This program rule if both fields are nor mandatory.

As a test, I created both data elements and the same program rule for a tracker capture on demo and it works well even both fields are mandatory, I do not know why it is not working for the event capture.

Any help is welcome

Thanks

Hi @dmbantu

DHIS2 usually prevents the user from having empty compulsory fields. Capture App and Android (tracker and event programs) will have the same behavior, not allowing you to hide fields set as mandatory. Also in Android, users must have the role to ignore required fields in order to sync empty mandatory data elements.

I suggest to remove the mandatory and create another rule making the field mandatory when is not hidden.

Hi @nancyesp,

I removed the mandatory from the program configuration, but I do not understand this part of your lastsentence: create another rule making the field mandatory when is not hidden. Can explain to me what I have to do? Like what I have to put in the program rule expression and Program rule action.

Thanks

You could create another rule with the oppossite expression “d2:hasValue( #{GS - Tem iluminacao adequada na Maternidade} ) && #{GS - Tem iluminacao adequada na Maternidade} == false” and then use the program action “Make field Mandatory” on the Problema da falta de iluminacao adequada na Maternidade data element, so it will only be mandatory when shown.

1 Like

Hi @nancyesp,

By creating another rule as you explained, Iam able to make DE Problema da falta de iluminacao adequada na Maternidade Mandatory. This is fine because is what I wanted, but it will be hard work as I have many data elements to be made mandatory through program rules.

NB: All yes/ no DEs elements should also be mandatory. Until now what we have configured to be mandatory is the field when the answer is no. What about if the user decides to skip a question?

In my use case none of the fields must be skipped.

Thanks again

Hi @dmbantu,

For all the mandatory DEs that could be hidden by a program rule, I would suggest to have another rule to make them mandatory (I don’t see any other way to make the ‘hide field’ action work). For the other DEs that are not affected by any program rule, then you can configure them as compulsory directly.

1 Like

Hi @nancyesp,

Thank you for your help. I will follow your instructions and get back soon if I get stuck.