Program Rule

Hola a todos,
Soy nuevo en la comunidad y nuevo en DHIS2.
Estoy realizando un formulario el cual va bien. Pero me encuentro con la dificultad de validar una regla que estoy generando.
Tengo un campo que responde a SI/NO, pero necesito generar una regla que me permita dejar en el siguiente campo un valor de acuerdo a la respuesta, es decir, si la respuesta es SI, dejar ingresar solo números y si es NO dejar un 0.
Gracias
Atte.,
agrimau

Hola @agrimau

Welcome to the community! :tada:

The Data Element which will be assigned a zero should already only allow numbers from the configuration DE value type, so my suggestion is to make two program rules:

The first program rule is to check that if the DE1 is No then assign value of 0 to DE2. The expression (DE1 == 'No') and action ‘Assign value’ with the value of the DE2 to be assigned equals to 0.

The second program rule is to show an error if the DE1 is a NO but the field is not equal to 0. This validation is necessary because it is possible for the value to be deleted even after it has been assigned using the first program rule. The expression could be (DE1 == ‘No’ && DE2 != 0 && (d2:count(DE2) >= 0)) and the program rule action, show error.

I hope this helps. Let’s see if someone from the community can respond to you in Spanish too. Gracias!