Limit number of Characters in tracker text data element field

Hi everyone, could you please guide how can we limit number of Characters in tracker text test data element field. Actually I know, I can select value type text, long text and letter but my in value type text we can enter 50,000 characters. But we want to limit it till 10,000 characters. Anyone please guide me how can this is possible in DHIS2.

1 Like

Hi @Saad

Welcome back to the community!

You might want to create a program rule with the d2:length function in the expression. For example,

(d2:length(#{dataElement}) <= 10000)

2 Likes

Thanks @Gassim for your quick response. Actually I am not so much experienced in DHIS2. Could you please share step by step guide or share some link. It will be great help. Thanks again.

2 Likes

Good morning.
Please follow these steps to achieve the said function.
STAGE 1.

  1. Create a ‘program rule variable’ by selecting the tracker program for which you would want to target a field.
  2. Give it a name, usually by referencing the field. This allows you to manage a large number of variables with a unique identifier.
  3. Select the source Type. Example: an attribute or data element. NB: attributes are fields assigned to a program “Profile”. To further explain, when you click the “register” button on a tracker program.
    Data Element on the other hand is data elements of domain type: “Tracker”. These are used when you want to create a stage in a program. (usually, to track an instance or create a progress report on a tracker instance.)

STAGE 2 - Involves three (3) steps

Step 1

  1. Create a corresponding program rule with the target program variable you have created in stage 1. NB: You can maintain the same name or append a specific option to identify it in case you would want to create different rules for different options from the same target program variable.
  2. Select the same program as used in creating the program variable.
  3. You can leave the trigger as default.
  4. Optionally, you can provide more description for reference later as well as priority

Step 2

  1. Click the “Enter program rule expression” tab.
  2. Click to expand “Variables”. Here you will see your program variable. Click to add it to the expression window and modify it according to @Gassim’s rule. ( (d2:length(#{dataElement}) <= 10000))

step 3

  1. Click the "Define program rule actions.
  2. Click the add button to define a rule. You can simply display a text to alert the end user.

I hope this help
If you still however find it challenging reach out to me at fosuheneandrews_at_gmail.com

2 Likes

2 posts were split to a new topic: D2:length function not working properly when new lines are found in LONG_TEXT DE