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

want to write a groovy script to locate the component on a page and change the one of the field value in it

Avatar

Level 4

I want to write a groovy script where I have to change one of the text field value in the component dialog box

 

-> I have the paths of the pages where this component has been used

-> the resourceType of component  is : /components/content/form/embed

->the text field name that need to be changed is : "formName"

->

rahul234dabas_0-1663746298287.png

->the text field value need to be changed using groovy script

 

Please help me out I am stuck on the implementation

 

Thank you

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
def buildQuery() {
    def queryManager = session.workspace.queryManager;
    def statement = "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/path/]) AND s.[sling:resourceType]= 'myapp/components/content/form/embed' AND s.[formName] is not NULL"
    queryManager.createQuery(statement, 'sql');
}


final def query = buildQuery();
final def result = query.execute();

result.nodes.each {
    node ->
        node.setProperty('formName', 'newvalue');
    }

session.save();
println 'Number Of Component Found :' + result.nodes.size();

View solution in original post

2 Replies

Avatar

Level 4

you can use the component conversion tool from the AEM modernization suit as well.

Here is how to use it:

https://opensource.adobe.com/aem-modernize-tools/pages/component/usage.html

 

you won't need to provide the page paths it will fetch it based on the component's resource type.

 

Avatar

Correct answer by
Community Advisor
def buildQuery() {
    def queryManager = session.workspace.queryManager;
    def statement = "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/path/]) AND s.[sling:resourceType]= 'myapp/components/content/form/embed' AND s.[formName] is not NULL"
    queryManager.createQuery(statement, 'sql');
}


final def query = buildQuery();
final def result = query.execute();

result.nodes.each {
    node ->
        node.setProperty('formName', 'newvalue');
    }

session.save();
println 'Number Of Component Found :' + result.nodes.size();