Step by step Example to set Default value for DE or attribue

Goal: Default nationality = Syrian, but user can change it by ticking a checkbox

Use case summary
program attribue :Nationality
Type: Text
Linked to Option Set (Nationalities)

program attribue : Not Syrian
Type: Yes only
Acts as a checkbox
When checked → user can change nationality

Program Rule:
Assign “SY” to Nationality only when (Not Syrian) is NOT checked

so if the user select check box the attribue will be editable >> change default value
Create Program Rule
Condition :
A{notsyrian} == false
Program Rule Action

Action type: Assign value
program attribue : Nationality
Value:‘SY’

the result :
if User does nothing Value stays SY
if User checks Not Syrian >> Nationality >> becomes editable and can change it

Hi @aalabdo

Thank you for providing this example! If you are using the latest supported versions of DHIS2 then this should work as expected.

Please did you test this rule after it’s changed to true then unchecked? What I mean:

  1. if User does nothing Value stays SY
  2. if User checks Not Syrian >> Nationality >> becomes editable and can change it
  3. what if the user checks Not Syrian and then unchecks it, will this change the default value back to SY?

If step three doesn’t work it means that A{notsyrian} is not being reevaluated to ‘false’ so we will need to double check that.

Thanks!

Hi @Gassim
my test environment on

|App Version|101.20.3|
|DHIS2 Version|2.41.4|

  1. if User does nothing Value stays SY
    yes
  2. if User checks Not Syrian >> Nationality >> becomes editable and can change it
    yes
  3. what if the user checks Not Syrian and then unchecks it, will this change the default value back to SY?
    yes
    the value “SY” will be assigned by program rule