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"
->
->the text field value need to be changed using groovy script
Please help me out I am stuck on the implementation
Thank you
Solved! Go to Solution.
Views
Replies
Total Likes
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();
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.
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();
Is there any easy way to update all resourcetype paths for all components in a project?
Example
myapp/components/content/form/embed
to
myapp2/components/content/form/embed
Views
Replies
Total Likes
Hi @gvaem
With groovy scripts, yes you can write any business logic and peform updates.
Views
Replies
Total Likes