Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How can I update multi valued property using groovy

Avatar

Level 5

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()
    }
}