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

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

Needs to save meta keyword and description programmatic

Avatar

Level 3

Hi Team,

 

Hope you are doing great.

Can anyone please help me how we save meta keyword pragmatically.

I have tried with this code but this is not works

 

 
Resource tagResource = resourceResolver.getResource("/content/ranosys-website/in/home/about-us/career/jcr:content");
Node myNode = tagResource.adaptTo(Node.class);
myNode.setProperty("cq:tags", "custom message bhagchand ");
Session session = resourceResolver.adaptTo(Session.class);
session.save(); 

 

 

Thanks in advance

Bhagchand

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @bhagchand 

 

Please create a session object first and try to add the property later.

 

Example here: https://helpx.adobe.com/ca/legal/product-descriptions/aem-cloud-service.html

 

Hope this helps!

 

Thanks,

Kiran Vedantam.

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @bhagchand,

 

To summarize your question, do you want to add a property to your resource programatically?

In your doPost method, make these changes.


Resource tagResource = resourceResolver.getResource("/content/ranosys-website/in/home/about-us/career/jcr:content");
Node myNode = tagResource.adaptTo(Node.class);
myNode.setProperty("meta", "your description");

resourceResolver.commit();

 

this will add a property to the mentioned node.

Avatar

Community Advisor

Hi @bhagchand,

 

If that's not working, I believe there are other things to discuss.

1. are you using a servlet/service to do the operation? if yes, what is your error log saying?

2. the operation may not get success if there are any issues with your ajax-call/trigger event.

3. if you are going with the session way, please create a Session object first and try to add the property later as @Kiran_Vedantam  said.


with the resourceResolver way, here is an example 

Thank you.

 

Avatar

Correct answer by
Community Advisor

Hi @bhagchand 

 

Please create a session object first and try to add the property later.

 

Example here: https://helpx.adobe.com/ca/legal/product-descriptions/aem-cloud-service.html

 

Hope this helps!

 

Thanks,

Kiran Vedantam.

Avatar

Level 10

Hi @bhagchand ,
Instead of using the jcr node API you should use the ModifiableValueMap. This is recommended. Try below snippet 

Resource tagResource = resourceResolver.getResource("/content/ranosys-website/in/home/about-us/career/jcr:content");
ModifiableValueMap map = tagResource.adaptTo(ModifiableValueMap.class);
map.put("cq:tags", "custom message bhagchand");
resource.getResourceResolver().commit();