# How to create entity attribute with generated value	based on others elements

**URL:** <https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383>\
**Category:** Support - Assistance technique\
**Created:** [14 November 2018 05:51 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383 "2018-11-14T05:51:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerard\_Bisama](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gerard_bisama/32/27281_2.png) [@Gerard\_Bisama](https://community.dhis2.org/u/Gerard_Bisama)\
**Post date:** [14 November 2018 05:51 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/1 "2018-11-14T05:51:22Z")

</div>

Hi everyone,

I am using tracker and I want to create a entity attribute with generated value that depending on other attributes values like :

- code of the orgunit assigned to program

- value of the field sex

- followed by random number of 4 digit.

Each of them separated with “-”.

Do some one have an idea on how to achieve this?

Thanks,

> **···**
>
> Gérard Bisama  
> Tel:+243810890810

---

<div class="post-metadata">

**Author:** ![em.hispvietnam](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/em.hispvietnam/32/191_2.png) [@em.hispvietnam](https://community.dhis2.org/u/em.hispvietnam)\
**Post date:** [14 November 2018 06:32 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/2 "2018-11-14T06:32:41Z")

</div>

Hi,

You can use Text Pattern [https://docs.dhis2.org/2.30/en/user/html/working-with-textpattern.html](https://docs.dhis2.org/2.30/en/user/html/working-with-textpattern.html)

Good luck!

> **···**
>
> **Em Le Hong**  
> DHIS2 Implementation| \*\*HISP Vietnam \*\*
> 
> [em.hispvietnam@gmail.com](mailto:em.hispvietnam@gmail.com) | **Skype:** [em.hispvietnam@gmail.com](mailto:em.hispvietnam@gmail.com)
> 
> ![](https://dhis2.b-cdn.net/uploads/default/original/2X/f/f33fa99fce139a9f5eeed9878c4246834a45e757.png)

---

<div class="post-metadata">

**Author:** ![Terence\_Scott](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/terence_scott/32/26898_2.png) [@Terence\_Scott](https://community.dhis2.org/u/Terence_Scott)\
**Post date:** [14 November 2018 09:46 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/3 "2018-11-14T09:46:01Z")

</div>

HI Gerard

Yes, this is possible with Text Pattern as mentioned previously.

One thing I would like to point out is that you create this all in the TE attribute. Therefore, create an attribute (e.g. Unique ID) and then select “Automatically generate”.

In the pattern, you can then enter the TextPattern that you require. Please note that to create a string, you separate with - and not with +. This is an example I created:

CURRENT\_DATE(yyyy-MM-ww)-“-”-ORG\_UNIT\_CODE(…)-“-”-“A”-SEQUENTIAL(###)

The “-” creates the dashes between the various variables, while the - separates the variables.

The number of dots and hashes in the OU code and Sequential relate to the number of items shown.

I hope this helps.

Kind regards,

Terence

> **···**
>
> Terence Scott
> 
> Global Alliance for Rabies Control (GARC)
> 
> Pan-African Rabies Control Network (PARACON) Steering Committee
> 
> [terence.scott@rabiesalliance.org](mailto:terence.scott@rabiesalliance.org)
> 
> [https://paracon.rabiesalliance.org](https://paracon.rabiesalliance.org)
> 
> Skype: tpscott1987

---

<div class="post-metadata">

**Author:** ![Gerard\_Bisama](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gerard_bisama/32/27281_2.png) [@Gerard\_Bisama](https://community.dhis2.org/u/Gerard_Bisama)\
**Post date:** [14 November 2018 12:27 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/4 "2018-11-14T12:27:05Z")

</div>

Thanks everyone for your response. I think the text pattern is option I prefer since it is quite clear and simple to configure. However I have this error when I want to register a new TE after adding a text pattern to the identifier attribute.

Error: Code is not implemented. I am using the version 2.27 is it due to that?

Thanks

Le mer. 14 nov. 2018 à 10:46, Terence Scott [terence.scott@rabiesalliance.org](mailto:terence.scott@rabiesalliance.org) a écrit :

> **···**
>
> Gérard Bisama  
> Tel:+243810890810

---

<div class="post-metadata">

**Author:** ![Terence\_Scott](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/terence_scott/32/26898_2.png) [@Terence\_Scott](https://community.dhis2.org/u/Terence_Scott)\
**Post date:** [22 May 2019 13:28 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/5 "2019-05-22T13:28:36Z")

</div>

Hi @Gerard_Bisama

This may be due to the fact that you have not attributed a Code to the thing that the pattern refers. E.g. if you have included the name of an Org unit into the pattern (as I did in my example above), then the OU needs to have a code attributed to it and that code needs to match what you have described in the pattern. In my example again, I used: “ORG\_UNIT\_CODE(…)” - this means that the OU will need a 3 letter code to refer as I have used 3 periods to signify the code.

I hope that this makes sense.

---

<div class="post-metadata">

**Author:** ![Waheed](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/waheed/32/44440_2.png) [@Waheed](https://community.dhis2.org/u/Waheed)\
**Post date:** [12 February 2021 11:37 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/6 "2021-02-12T11:37:49Z")

</div>

> [@Terence\_Scott](#):
>
> TE attribute

exactly this is what i want to have WBG-WAU-JTH-10001 Where WBG is the Abbreviation of the State and WAU for the County and JTH is for the facility and follow by the number which will increment it self automatic whenever there’s a new enrollment.  
Secondly I will need to learn the skip logic in dhis2.  
and if you have pdf tutorial or video share it with me, because the previous link that you have share it not that easy to understand.  
Best Regards

---

<div class="post-metadata">

**Author:** ![Waheed](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/waheed/32/44440_2.png) [@Waheed](https://community.dhis2.org/u/Waheed)\
**Post date:** [16 February 2021 14:41 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/7 "2021-02-16T14:41:21Z")

</div>

Dear Terence, I hope your doing well,  
If you have a video tutorial or pdf Tutorial please share it with us because i tried to implement what you have said and I couldn’t implemented well.  
Best Regards

---

<div class="post-metadata">

**Author:** ![redet](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/redet/32/41782_2.png) [@redet](https://community.dhis2.org/u/redet)\
**Post date:** [12 July 2023 08:43 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/8 "2023-07-12T08:43:45Z")

</div>

The documentation is now moved to [DHIS2 Tutorials - DHIS2 Documentation](https://docs.dhis2.org/en/use/user-guides/dhis-core-version-240/additional-information/dhis2-tutorials.html#textpattern-syntax)

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [13 July 2023 07:10 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/9 "2023-07-13T07:10:15Z")

</div>

Thank you for the updated link @redet!

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [13 July 2023 07:10 UTC](https://community.dhis2.org/t/how-to-create-entity-attribute-with-generated-value-based-on-others-elements/5383/10 "2023-07-13T07:10:19Z")

</div>

Old topic from 2018. If anything new comes up or if you have a question, please open a new topic. If you believe this topic should be reopened please DM moderators.
