I want to access a Data Element from exact previous event in a repeatable tracker stage, whether it has a value or is empty.
Steps to reproduce:
I have a program rule variable (call it PRV) with a source type of “Data element from previous event”.
In the first event, I fill X in the data element.
In the second event, the PRV is equal to X. Now, I submit the second event with empty data element.
In the third event, the expected behavior for PRV is to return data element from the previous event which should be empty, but the PRV returns X from the first event.
So you are expecting to receive the ‘data element’s value from the latest previous event (even if the value is null)’ but it is giving you the 'data element’s value from that latest previous event when the value is not null). I don’t know whether this is the expected behavior or not, I will triage this to @dhis2-tracker as you have correctly tagged them.
Yes, exactly as you phrased it. I believe the latest state of the DE is what expected be propagated instead of any previous event. To give a bit of context, below scenario led me to this issue:
I have an optional DE with an option set in a repeatable stage. There is a program rule that auto-fills this DE based on the previous event. Everything works fine unless the user clears the DE and doesn’t select any option from the list. In that scenario, in the next event, the DE is assigned selected option from previous-previous-event instead of being empty from the previous-event.
Thanks @malekpour for the additional info! The team is now aware of this and as soon as I get a final response about this either I or someone from the @dhis2-tracker will reply.
If the current situation is causing a blocker. For now, I would like to suggest a workaround such as using a “program rule” that will fill another data element with a value such as “no option selected” so that in the follow-up event, if that new data element contains “no option selected”, you will continue your workflow as usual.
Thanks @Gassim for the follow-up and suggested workaround. Although having “helper” data element can relieve the issue, it’s not a clean and proper way IMHO. For instance, below is a screenshot of current implementation which includes many “auto-filled data” for these “helper” DEs:
Hi. We are experiencing the same issue. Is there a ticket for this @Gassim ?
The documentation says clearly “previous event value”, not “any previous event until DHIS2 finds a non null value”.
In the meantime, @malekpour , I suggest this workaround.
Find a DE which is always entered or create a hidden one and auto-populate it (for example with the date of the current event). Say your PRV is called prevMed and the DE which is always populated has another PRV linked also to the value of that DE in the previous event, eg prevEventDate. You can do in your PR condition d2:lastEventDate(‘prevMed’) == d2:lastEventDate(‘prevEventDate’). I checked and d2:lastEventDate also gives you the date of the last event for which the DE associated to the PRV has a value.
With a diagram:
When entering event 3, I see prevMed (DE ‘Med’) = ‘Losartan’ → Incorrect
Event 2 on 2026-02-28: DE ‘Med’ = null (no value provided)
Event 1 on 2026-01-31: DE ‘Med’ = Losartan
But
d2:lastEventDate(‘prevMed’) = 2026-01-31
d2:lastEventDate(‘prevEventDate’) = 2026-02-28
Since the dates don’t match, my PR is not triggered and now when entering data for Event 3, prevMed is empty.