Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

Need Help: Adding Dialog Field to 2000+ Existing Pages

Avatar

Level 2

Need Help: Adding Dialog Field to 2000+ Existing Pages

I've added a new field to a component dialog used across ~2000 pages in our AEM instance.

Issue:

New field appears correctly on newly created pages

For existing pages, field only appears after reopening/closing the dialog

Manually reauthoring 2000+ pages isn't feasible. Need efficient solution to add this property to all existing component instances without manual intervention.

Looking for an out-of-the-box AEM solution or existing feature that can handle this dialog property update without extensive scripting. Prefer a configuration-based approach if available.

Environment:

AEM version: [6.5]

Dialog: [Coral UI 3/Touch UI/Classic]

Has anyone solved this problem at scale? Sample scripts would be appreciated!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @SivaNa3,

I think the easiest and most effective option is to use Groovy console.

Below is sample script create for we.retail but it can be changed for your purposes:

  1. Replace /content/we-retail with your content path.
  2. Replace weretail/components/content/heroimage sling resource type with your component resource type.
  3. Replace newProp with your newly added prop.
  4. Replace newPropValue with value you would like to be set in your new prop on every page.

 

import javax.jcr.query.Query
import org.apache.sling.api.resource.ModifiableValueMap

def DRY_RUN = true

def QUERY = """SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/we-retail])
        AND s.[sling:resourceType] = "weretail/components/content/heroimage"
        AND s.[newProp] IS NULL"""

resourceResolver.findResources(QUERY, Query.JCR_SQL2)?.each { resource ->
    def valueMap = resource?.adaptTo(ModifiableValueMap)
    if (valueMap) {
        valueMap.put("newProp", "newPropValue")
        println "Component ${resource.path} has been updated"
        if (!DRY_RUN) {
            resourceResolver.commit()
        }
    }
}

 

You can DRY_RUN flag value to control if changes will be saved or not.

View solution in original post

6 Replies

Avatar

Correct answer by
Community Advisor

Hi @SivaNa3,

I think the easiest and most effective option is to use Groovy console.

Below is sample script create for we.retail but it can be changed for your purposes:

  1. Replace /content/we-retail with your content path.
  2. Replace weretail/components/content/heroimage sling resource type with your component resource type.
  3. Replace newProp with your newly added prop.
  4. Replace newPropValue with value you would like to be set in your new prop on every page.

 

import javax.jcr.query.Query
import org.apache.sling.api.resource.ModifiableValueMap

def DRY_RUN = true

def QUERY = """SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/we-retail])
        AND s.[sling:resourceType] = "weretail/components/content/heroimage"
        AND s.[newProp] IS NULL"""

resourceResolver.findResources(QUERY, Query.JCR_SQL2)?.each { resource ->
    def valueMap = resource?.adaptTo(ModifiableValueMap)
    if (valueMap) {
        valueMap.put("newProp", "newPropValue")
        println "Component ${resource.path} has been updated"
        if (!DRY_RUN) {
            resourceResolver.commit()
        }
    }
}

 

You can DRY_RUN flag value to control if changes will be saved or not.

Avatar

Community Advisor

Hi @SivaNa3 ,

Do you want to return a default value (static value ) even without reopening dialog and if field is mandatory then you can check for null value in the sling model and return default static value from sling model. Then it will work.

Else we have to write script.

Thanks

Avatar

Community Advisor

Hi @SivaNa3 ,

Try below solution:

Update JCR Nodes via Groovy Console

Here’s a refined and production-safe version of the script tailored for your scenario:

import javax.jcr.query.Query
import org.apache.sling.api.resource.ModifiableValueMap

def DRY_RUN = false  // set true to test without saving, false to commit

// CONFIGURATION
def CONTENT_ROOT = "/content/your-site" // replace with your site's root path
def COMPONENT_RESOURCE_TYPE = "your/components/content/yourcomponent" // replace with actual component path
def NEW_PROPERTY_NAME = "yourNewField"
def NEW_PROPERTY_VALUE = "defaultValue" // set default value as needed

def QUERY = """
    SELECT * FROM [nt:unstructured] AS s 
    WHERE ISDESCENDANTNODE(['${CONTENT_ROOT}']) 
    AND s.[sling:resourceType] = '${COMPONENT_RESOURCE_TYPE}' 
    AND s.[${NEW_PROPERTY_NAME}] IS NULL
"""

resourceResolver.findResources(QUERY, Query.JCR_SQL2)?.each { resource ->
    def valueMap = resource?.adaptTo(ModifiableValueMap)
    if (valueMap) {
        valueMap.put(NEW_PROPERTY_NAME, NEW_PROPERTY_VALUE)
        println " Updated: ${resource.path}"
        if (!DRY_RUN) {
            resourceResolver.commit()
        }
    }
}

println "Script execution complete."

 

Benefits:

  - No need to manually reauthor 2000 pages.

  - Keeps dialog definitions untouched — updates only the JCR nodes.

  - Safe to run on Author and publish via MSM or Manage Publication.


Notes:

  - Run only in Author, never on Publish.

  - Take a backup or run a dry run first (DRY_RUN = true) before committing.

  - Works only if the field is persisted in the JCR (not dynamically derived only in Sling Models/UI).


Regards,
Amit

Avatar

Level 4

Hi @SivaNa3 ,

 

My response also more or less same, use a script to add/update the jcr content with the property, it is one time activity.

also i can share a Java sample fiddle here and you shall use this console to run that

http://localhost:4502/etc/acs-tools/aem-fiddle.html#new-java

Note- Please check & update the script as per your use case.

After update, make sure -

  1. You are not replicating language masters pages.
  2. you are not replicating unpublished pages.
  3. you are not replicating pages under staging (edited after last publish).

 

Thanks,

Raju.

Avatar

Community Advisor

Hi @SivaNa3 

 

You can refer the groovy scripts shared by @lukasz-m & @AmitVishwakarma .

 

If you are doing a content migration project or need to do this more frequently, you can also explore using https://github.com/valtech/aem-easy-content-upgrade . Its built on top of groovy console and has additional features.

 

Hope this helps!


Thanks

Narendra

Avatar

Community Advisor

@SivaNa3 You can create a simple groovy script to update all component instances.

Additionally, to avoid breaking your pages/components. add a default value to this new field.