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

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

How to add/update properties in an existing node?

Avatar

Level 2

I have some nodes under /etc on my repository which I'd like to insert or change the values of some properties in it. But I neither want to affect nor know the value of other properties in the very same node.

What  is the best way to do this task?

I was able to create a new sub-node by uploading a package and installing it using the Package Manager, but is not quite what I need.

Can anyone shed some light?

Thank you very much.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is sample one

Node n = session.getNode("/content/project/home"); n.setProperty("Name","AEM"); Node n = session.getNode("/content/project/home"); String s = n.getProperty("Name").getString();

For adding you can directly call setProperty method, if that property exist it will be updated else a new one will be added.

3 Replies

Avatar

Level 10

To change the properties of a JCR node, use the JCR API. You can write app logic to modify existing node's props. 

Avatar

Correct answer by
Level 10

Here is sample one

Node n = session.getNode("/content/project/home"); n.setProperty("Name","AEM"); Node n = session.getNode("/content/project/home"); String s = n.getProperty("Name").getString();

For adding you can directly call setProperty method, if that property exist it will be updated else a new one will be added.