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
BedrockMission!

Learn More

View all

Sign in to view all badges

Update component node using groovy script in aem

Avatar

Avatar
Level 1
gayatrik8153299
Level 1

Likes

0 likes

Total Posts

25 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
gayatrik8153299
Level 1

Likes

0 likes

Total Posts

25 posts

Correct Reply

0 solutions
View profile
gayatrik8153299
Level 1

28-09-2020

Hi All,

We have one requirement need to write groovy script to update component node.

1.need to find the list of pages where tab component been used

tab component has multifield where each field has tab id and tab name and can author upto 5 tabs.

2. Once we get the list of pages, we need to find the component with node name navigationtabs

as shown in the below screenshot.

ex: page /content/we-retail/auotmation-support-program has tab component with node name navigationtabs and under this navTabList (multifield name) node will be there and under this 1,2,3,4,5 with nodes if author added 5 tabs. here only 2 tabs are added hence only 1 and 2 node are created.

if we take node 1 has navId and navName and need to get property navId and like that from each nodes 1,2,3,4,5 if there were 5 nodes.
then get the navId value and it should be same as node created under node navigationtabs.
here in the screenshot can see navId value is "Vendor" and this value should get updated for "By Vendor" node.

 

gayatrik8153299_0-1601282238214.png

Please suggest on how to write groovy script to update node.

 

1.find the list of pages used tab component

2.then find the node navigationTabs and then find the navTabsList node under that.

3.then find the nodes 1,2,3,4,5 if exists under navTabsList

4.check if navId has property and get the navId property from each nodes 1,2,3,4,5

5.once we get the navId value, find under navigationTabs node and should be same as navId Value under navigationTabs node else it should be updated  with navId value.

 

we are using AEM 6.4.5 version

Thanks,

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

505 likes

Total Posts

642 posts

Correct Reply

213 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

505 likes

Total Posts

642 posts

Correct Reply

213 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

28-09-2020

Hi @gayatrik8153299,

For updating node name, we need to make use of move method from Session API - javax.jcr.Session

  • node.getSession().move(scrPath, destPath);

For your specific use case,

Assumption : (based on the screenshot shared)

Node that needs to be updated say "By Vendor" under navigationtabs is the same as navName property value. Have used this value to frame srcPath for move method mentioned above (In other words, node under navigationtabs is changed from navName value to navId value)

Note:

While executing in higher environments, have a content back up and then execute the script (in phases based on the content volume)

Answers (1)

Answers (1)

Avatar

Avatar
Give Back 10
MVP
Varun_Shakya
MVP

Likes

119 likes

Total Posts

96 posts

Correct Reply

24 solutions
Top badges earned
Give Back 10
Ignite 3
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Give Back 10
MVP
Varun_Shakya
MVP

Likes

119 likes

Total Posts

96 posts

Correct Reply

24 solutions
Top badges earned
Give Back 10
Ignite 3
Ignite 1
Give Back 5
Give Back 3
View profile
Varun_Shakya
MVP

28-09-2020