3.3.1+ Android Issues with Program Rules hiding and making mandatory consistently

Using 3.4.2, 3.4.1, 3.3.1

I have a tracker program with some simple show hides based on a Boolean Yes/No DE within a single program stage. The trigger of the program rules are ${DE} and !#{DE}, and hides a number of DEs and makes others mandatory based on the DE’s response (respectively).
For the example:
IF DE X,
Hide DE Y
Make mandatory DEs P,Q,R,S

If not DE X,
Make mandatory DE Y
Hide DEs P,Q,R,S

What we are seeing in 3.4.2, 3.4.1, 3.3.1 is that DE X is neither being hidden nor being made mandatory (i.e. doesn’t have the * and doesn’t show an error when saving without a value). Interestingly, though, the other DEs (P,Q,R,S) function appropriately (from the same program rule). Additionally, when DE X (i.e. when DE Y should be hidden) the value selected in DE Y gets removed each time. When not DE X, the value is stored. This also feels like it is “trying” to hide the DE, but unable to.
Other notes:

  • This is not happening on Capture in the most recent version, nor is it happening in android 2.8.2/2.9.1 (the show/hide works fine).
  • I have looked through the API to verify if any other program rules are firing on this DE specifically to make it behave differently, and see none.
  • DE Y (the DE which is seemingly unaffected by Program rules) is in the same programStageSection as DE X (the DE which controls the firing). I did move the DE to another programStageSection, and there was no change in effect.
  • There are other DEs that get shown/hidden/made mandatory that also have optionSets associated (I thought perhaps this was a meaningful variable)
  • This is happening across devices, across servers with the same program.
  • Again, this is NOT happening on 2.9.1, 2.8.2, or on Capture
  • This is not the last DE in the program, though it is the last DE in the programStageSection.

Thanks, Matthew, for documenting this issue so clearly.

I think this deserves further investigation because it affects the consistency of Program Rule evaluation between Android Capture and the web Capture app, particularly in Tracker programs.

The most concerning behavior is that the field remains visible even when the Hide field action should apply, while its selected value is cleared. At the same time, the Make field mandatory action appears not to update the field’s mandatory indicator or prevent saving when the value is missing. This suggests that field visibility, value handling, and mandatory validation may not be staying in sync on Android.

A few points that could help narrow down the issue:

  1. Field configuration: Confirm whether DE Y is marked compulsory in the program stage configuration. Previous reports suggest that a field configured as compulsory may not be hidden correctly on Android, even when a program rule attempts to control its visibility.

  2. Rule evaluation and priorities: Verify whether the two mutually exclusive rules are evaluated consistently when DE X changes between Yes and No, including when the field initially has no value.

  3. Value persistence: Investigate why the value of DE Y is cleared when the hide condition becomes active, even though the field remains visible. This may be an important clue to how the rule action is applied.

  4. Regression testing: Since the behavior differs between Android Capture 3.3.1–3.4.2 and the web Capture app, reproducing it with the same program configuration across versions would help isolate the regression.

Ideally, the investigation should establish whether the issue is related to the interaction between HIDEFIELD and MANDATORYFIELD, the field’s configuration, or a difference in how Android evaluates and renders program rule actions.

I would be interested in testing a minimal reproducible Tracker program if one can be shared. A sanitized program configuration, together with the exact Android app version and server version, could help the community narrow down the cause.

Expected behavior: Android Capture should consistently apply the same visibility and mandatory rules as web Capture, without unexpectedly clearing field values or allowing records to be saved when a rule requires a value.

Thanks to the DHIS2 Android team and community contributors for investigating this. Consistent program rule behavior is essential for reliable data collection and data quality in field settings.

Hi @Matthew_Boddie

It seems that we are addressing several issues here. To begin with, this topic is already triaged to the @dhis2-android team; however, let me see what findings I might be able to add.

Might be related to this Jira ticket: Program rule warning is not triggered when navigating directly to a Yes/No field - DHIS2 ANDROAPP-7825

I have a feeling that this means it’s not being triggered. Would you like to change the action to see if it’s being triggered at all? If it is then it might be another issue..

Thanks!

Thanks @Gassim for the thoughtful response.

The ticket you’ve found seems to be talking about program rule warnings to boolean DEs; this is different insofar as its a boolean source DE that should be triggering hide field and make field mandatory. Also, notably, this hide/make mandatory is functioning for other DEs, just not for one in particular.

Here are 2.8.2, 3.3.1 ,and 3.4.1 experiences for the same user, same program. “If not accepted, why?” is the DE with the issue, i.e. not being affected in 3.3+, but being appropriately hidden/made mandatory in 2.8.2 and 2.9.1.1.

2.8.2 experience
3.3.1 experience
3.4.1 experience

Hi Matt!

Are there any program rules that include HIDEOPTION, HIDEOPTIONGROUP or SHOWOPTIONGROUP for that data element?

Hi Karoline! Long time.

No, there are no option actions associated with the DE. I did try and make the DE a text field, put it into another programStageSection, but didn’t have any difference in functionality.

Hi @Matthew_Boddie!

Following up on Karoline’s question, the only way we could reproduce this exact behavior was by adding an option related rule action (HIDEOPTION, HIDEOPTIONGROUP or SHOWOPTIONGROUP) that targets the same data element.

3.5.0
android_3_5_0

3.5.1
android_3_5_1

This comes from a change in how the app refreshes option sets after evaluating rules , introduced in 3.1.0.1. It’s fixed in 3.5.1, which is due at the end of the month. Until then, removing that “option action” (or replacing it with a showerror validation) should make the hide/mandatory rules work again.

Could you check whether “If not accepted, why?” is targeted by any option action? If that’s not your case, is it possible for you to share the program metadata?

Thanks

@nancyesp Appreciate all the time you and the team have spent here.
I made my first statement on a false premise which is that the programRuleActions could be filtered by pointing at the dataElement.id, which was a bad error on my part. When I looked more into it I realized that, indeed, there were HIDEOPTION programRuleActions associated with the OptionSet associated with the dataElement.

Interestingly, when I did a workaround to test this, I set up a new OptionSet and attached it to the existing dataElement, and there was no change (after syncing configuration and seeing that the optionSet had been swapped, the same bug existed). When I deleted the account and logged back in, however, it became functional. What I haven’t tested is if I were to create and then remove hideOption programRuleActions if it would also require a full delete and log in.