Groovy script not working as expected - Trying to update cq:tags
Hi Everyone,
I am trying to use AEM Groovy Console to add a new tag to a page's existing cq:tags property.
Below is my code:
def page = getPage("/content/mysite/en/sample")
def modifiable = page.node
def tagToAdd = "myproject:custom/tag"
def existingTags = modifiable["cq:tags"] ?: []
if (!existingTags.contains(tagToAdd)) {
existingTags << tagToAdd
modifiable["cq:tags"] = existingTags
}
I expect this to add the tag only if it's not already present. But it doesn't work in some cases - especially when the page already has one tag.
Can anyone tell what is wrong?