How to add a unique ID to the already created tags | Community
Skip to main content
Level 2
October 24, 2024
Solved

How to add a unique ID to the already created tags

  • October 24, 2024
  • 3 replies
  • 904 views

HI All,

 

I have a requirement, where I have a large number of tags in my system under cq:tags example (/content/cq:tags/exampleTag), but these tags have only title property and description property in it, I need to add a new property as ID for it, a one similar to jcr:uuid (either this is also fine).

 

The id property should have unique values for each tag and should be created for all the tags and sub-tags of the selected tag.

 

Do we have any configuration settings for it, to create a ID property for a already existing tags, or any kind of code that we could run to create the ID's for the tags.

 

All suggestions are welcome.

 

Thanks, 

Nirmal

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Tethich

Hi @nirmal_kumar1 

As for my knowledge there is no ootb solution nor some utility out here that can do this.
But it sounds like an easy thing to achieve.

First, it seams this is a one time operation that you need to do on the existing tags.
Second, I assume from now on whenever you add a new tag, you will want to have this ID property being added automatically on it.


Me, I would go with a OSGi service that iterates through your tags and adds the unique ID property for each. You can use whatever algorithm to generate such IDs.
Then I would write a simple Sling servlet, that can afterwards be invoked in anyway you prefer afterwards, and that in its turn calls the service.
And last I would write a simple Sling listener that watch over newly created or copied tags and adds the ID property on them.
Of course that the logic to generate a unique ID can live in some utility class, and be reused in both service and listener.

I hope this helps.

3 replies

Tethich
Community Advisor
TethichCommunity AdvisorAccepted solution
Community Advisor
October 24, 2024

Hi @nirmal_kumar1 

As for my knowledge there is no ootb solution nor some utility out here that can do this.
But it sounds like an easy thing to achieve.

First, it seams this is a one time operation that you need to do on the existing tags.
Second, I assume from now on whenever you add a new tag, you will want to have this ID property being added automatically on it.


Me, I would go with a OSGi service that iterates through your tags and adds the unique ID property for each. You can use whatever algorithm to generate such IDs.
Then I would write a simple Sling servlet, that can afterwards be invoked in anyway you prefer afterwards, and that in its turn calls the service.
And last I would write a simple Sling listener that watch over newly created or copied tags and adds the ID property on them.
Of course that the logic to generate a unique ID can live in some utility class, and be reused in both service and listener.

I hope this helps.

arunpatidar
Community Advisor
Community Advisor
October 24, 2024

Hi @nirmal_kumar1 
You can try groovy script to update tags id in the content as well as add to tags.

Arun Patidar
anupampat
Community Advisor
Community Advisor
October 25, 2024

Hi @nirmal_kumar1 ,

 

Either a groovy script or a MCP needs to be written for this. Iterate through all the tags and add a random number or alphanumeric value.

More about MCP - https://kiransg.com/tag/mcp/

 

Regards,

Anupam Patra