Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

How can I update multi valued property using groovy

Avatar

Level 6

How can I update multi valued property using groovy, ex: cq:rolloutConfig is of String[] and i want to add values to this field using groovy.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Shaheena_Sheikh,

In groovy you can use code like this:

Property property = node.getProperty("cq:rolloutConfig")
if (property?.isMultiple()) {
    String [] values = property?.getValues() as String []
    if(values) {
        values += "new value"
        node?.setProperty("cq:rolloutConfig", values)
        save()
    }
}

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @Shaheena_Sheikh,

In groovy you can use code like this:

Property property = node.getProperty("cq:rolloutConfig")
if (property?.isMultiple()) {
    String [] values = property?.getValues() as String []
    if(values) {
        values += "new value"
        node?.setProperty("cq:rolloutConfig", values)
        save()
    }
}