Create and modify node inside crx using js use api | Community
Skip to main content
November 4, 2021
Solved

Create and modify node inside crx using js use api

  • November 4, 2021
  • 3 replies
  • 2800 views

Hello Guys im new on AEM, im using AEM 6.5, is it possible to create or modify node inside crx aem using js use api not java? i couldnt find related article on internet, can u give me some example how to do it, or maybe related article. thank you for your answer.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Siva_Sogalapalli

You can try getting resource & resource resolver in js and then modify nodes.

 

var resourceResolver = resource.getResourceResolver();

 Also, you can check below for additional info:

https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/use-api-javascript.html?lang=en


Hope this helps.

 

another question is, it would be easy to write backend logic at java-sling model level. What is reason you're using js use api?

thanks 

3 replies

Siva_Sogalapalli
Community Advisor
Siva_SogalapalliCommunity AdvisorAccepted solution
Community Advisor
November 4, 2021

You can try getting resource & resource resolver in js and then modify nodes.

 

var resourceResolver = resource.getResourceResolver();

 Also, you can check below for additional info:

https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/use-api-javascript.html?lang=en


Hope this helps.

 

another question is, it would be easy to write backend logic at java-sling model level. What is reason you're using js use api?

thanks 

November 5, 2021

Thank you for the answer and suggestion,actually, im currently at research stage, since im not really familiar with java yet, im trying to explore is it possible or not. But if its not then maybe i have to use java.

VeenaVikraman
Community Advisor
Community Advisor
November 4, 2021

@hendrahaqq Since you are new to AEM , I would say please restrain from doing node manipulation using JS ( though I am not sure if you can do it as I have never tried it myself). The right way to do any kind of node manipulation is to use service users in your backend Java. 

November 5, 2021

Thank you for the answer and suggestion, actually, im currently at research stage, since im not really familiar with java yet, im trying to explore is it possible or not. But if its not then maybe i have to use java.

joerghoh
Adobe Employee
Adobe Employee
November 4, 2021

With "Use API" you are probably referring to HTL scripts from which you reference these javascript scriptlets. And that means that this execution most likely should happen during the page rendering.

 

Basically that's probably, but you need to make sure that the user has enough permissions to write to the repository at the correct location. And for anonymous users that's definitely never the case.

November 5, 2021

Thank you for the answer,actually, im currently at research stage, im trying to explore, is it possible or not.