Skip to main content
Level 3
Apr 22, 2022 9:34 AM UTC
Solved

Needs to save meta keyword and description programmatic

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Kiran_Vedantam
Kiran_VedantamAccepted solution
New Participant
Apr 22, 2022 1:37 PM UTC

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.

5 replies

Anish-Sinha
Employee
Apr 22, 2022 3:51 PM UTC

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();
Translate
Kiran_Vedantam
Kiran_VedantamAccepted solution
New Participant
Apr 22, 2022 1:37 PM UTC

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.

Translate
B_Sravan
New Participant
Apr 22, 2022 11:02 AM UTC

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.

Translate
bhagchandAuthor
Level 3
Apr 22, 2022 11:16 AM UTC

Thanks, but this is alos not work

please share any other solution

Translate
B_Sravan
New Participant
Apr 22, 2022 2:11 PM UTC

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.

 

Translate