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!
Solved! Go to Solution.
Views
Replies
Total Likes
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:
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.
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:
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.
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
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
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 -
Thanks,
Raju.
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
@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.
Views
Likes
Replies
Views
Likes
Replies