Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Needs to save meta keyword and description programmatic

Avatar

Level 4

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

Level 4

Thanks, but this is alos not work

please share any other solution

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

Employee Advisor

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();