Tracked entity attribute Pattern Error

Good morning, I am developing a tracker program and I have created Tracked entity attribute with a pattern ORG_UNIT_CODE(…)+"-"+ SEQUENTIAL(###)"/"CURRENT_DATE(dd-MM-yyyy) and the output is 920-002/31-03-2022 instead of the CES_JUB_JTH-002/31-03-2022 what could be the issue, you’re quick response will be highly appreciated.

Hi @Waheed1994,
Good evening! Sorry for not being as fast as you might have expected.

Could you try ORG_UNIT_CODE() without the dots, what value do you get? Then search for this value in your API: Your_Instance_URL/api/organisationUnits?paging=false&fields=code,name,href and please search for CES_JUB_JTH can you find it?

If you can’t find these values could you try again in a different browser (or make sure your cache is cleared using the browser cache cleaner app) and then reload apps as well as clear application cache from the Data Administration app. After doing maintenance, please search again.

We need to know more about the situation to debug and understand the issue so please post back to the community with any updates! Thanks!

1 Like

Dear Mr Gassim thank you for replying to my post find attached the screenshot of the API search

I tried to change the pattern from ORG_UNIT_CODE(…)+"-"+ SEQUENTIAL(###)"/“CURRENT_DATE(dd-MM-yyyy) to ORG_UNIT_CODE()+”-"+ SEQUENTIAL(###)"/"CURRENT_DATE(dd-MM-yyyy) it give me error massage Could not generate value: Value is invalid: ORG_UNIT_CODE → 920201001 and when I change the OU code from one facility it work fine.
is that mean I need to change OU Code for each facility one by one??? or is there’s an easy way to do that??? secondly the idea is that if the user selects a facility in Central Equatoria State, Juba County and the Facility Name is Juba Teaching Hospital the code most be CES_JUB_JTH-002/01-04-2022 and this code should generate itself automatically based on the facility location. your quick support will be highly appreciated.

1 Like

Hi @Waheed1994,
Thank you for the detailed answer! I see that the ORG_UNIT_CODE you are requesting is

When you use ORG_UNIT_CODE(…) it shows only the first three characters in the CODE (if you did four it will show the first four, but according to the docs, if you leave it empty it will display the complete CODE):

Maybe the organisationUnit that you are requesting doesn’t have the CODE CES_JUB_JTH that you are requesting. Please search in that list you took a screenshot of for the Juba Teaching Hospital? Is the code and name saved as required? Please check!

Only the ones that weren’t saved with the correct code, I guess; however, I think it might be possible to easily update the codes using either the import/export app [export orgnisation units, update codes, import] or the API.

Hope this helps! Thanks! :+1:

1 Like

Thank you Mr. Al Gassim, for your comprehensive feedback, I have implemented the concept of updating the OU code and it’s working fine, I would like to know if it’s possible to share the API for updating the OU code.
Thanks again

1 Like

Dear Mr Gassim, Greetings,
I would like to ask you if there’s a way for updating the OU code in the DHIS2 through API, the total number of facilities that need to be updated is more than 2000+.
your quick response will be highly appreciated.

1 Like

Hi @Waheed1994,
I apologize for taking this long. I had to make sure I test this method before I post it to you. It is an easy process. Please do you have that info ready in CSV format (this might be the most important task for you to put together)? Here’s the easiest way I found.
First, using the Import Export app, export the Metadata of the Organisation Units as CSV format. Open the the CSV file and order the columns in the proper CSV format name,id,code like the screenshot:

Replace the code with the proper code that you want. When testing I replaced OU_651071 to OU_A651071 and it worked fine (replacing OU_# to OU_A# for all orgnisation units.)
Second, when this file is ready, go back to the Import/Export app and select Metadata import and make sure the Identifier is UID (since you’ll be updating the Code don’t select code)

These are the settings I used when updating the codes, please review accordingly. I recommend you test this in a test instance first and if the desired result is what you see then go on to the production. I used play instance as you can see. (:

Sorry for taking longer than expected, @Waheed1994!

I hope this process will work smoothly for you but please feel free to post back if you have any questions.

Thanks! :+1:

1 Like

Thank you Mr Gassim for your comprehensive feedback I really appreciate that, if possible can you update me on how to update the OU Code through the API I will be more grateful to you.
Thanks in advance