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

Add a new property

Avatar

Avatar
Validate 1
Level 1
aemninja
Level 1

Likes

2 likes

Total Posts

53 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
aemninja
Level 1

Likes

2 likes

Total Posts

53 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
aemninja
Level 1

13-04-2021

Hello All - I am looking for Curl command to add a property in all the pages under the specific folder in JCR. if the property exists, it should ignore it else it should add it.

 

Path:/content/test/en

Property: testprop = true

 

Also is there any utility provided by ACS to add a specific property without using CURL command?

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

591 posts

Correct Reply

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

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

591 posts

Correct Reply

231 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

14-04-2021

@aemninja,

There is no AEM out of the box curl command that allows you to update a sling resource inside of the crx/de, however, you can create a Sling Servlet that can accept specific parameters, which allows you to manipulate and change properties using the Sling CRUD API.
Sling CRUD API - https://sling.apache.org/documentation/the-sling-engine/sling-api-crud-support.html

The servlet will accept parameters as "resourcePath", "prop", "val".
example: [POST] /bin/my-site/update-resource [REQUEST-BODY]resourcePath=/content/dam/my-site/folder;prop=testprop;value=true

Servlet doPost example:

 

 @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
        ResourceResolver resourceResolver = getResourceResolver();
        String path = extractPostRequestBody("resourcePath");
        String propName = extractPostRequestBody("prop");
        String propVal = extractPostRequestBody("val");
        Resource myResource = resourceResolver.getResource(path);
        ModifiableValueMap properties = myResource.adaptTo(ModifiableValueMap.class);
        properties.put(propName, propVal);
        resourceResolver.commit();
    }

 

 

 

 

Answers (1)

Answers (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

560 likes

Total Posts

677 posts

Correct Reply

194 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

560 likes

Total Posts

677 posts

Correct Reply

194 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

13-04-2021

Hi @aemninja 

 

Unfortunately there is no such utility available that can update any additional property to all the pages under a specific folder.

How frequently you need this property to be updated?

  1. If this is going to be one time update, I will suggest to go with a servlet which will just take the source folder path as a parameter and iterate over all the pages available under the folder. If any page found, try to look for the property you are trying to add and if it does not exist then add it. If it exists, then skip it.
  2. If it's going to be done more frequently, then you can go by authoring by adding another field into the page property dialog and then using the inheritanceValueMap, in this way you can author only on the parent page and all the child page will inherit the same property. If you want to change in future you can change at one place, or if you want to override at a child page level also can be done.

Hope this helps!

Thanks