I'm working in CQ5.5 on a custom workflow in an ecma file to do the following:
Given the creation of a page of template type A, automatically create a page of template type B and populate some of the content from page A into page B. I have no problem creating the page but when I go to insert content, it is not giving me a node called test under jcr:content, like I would expect. Anyone have any ideas?
//this code works
var resolver = sling.getService(Packages.org.apache.sling.jcr.resource.JcrResourceResolverFactory).getRe sourceResolver(session);
var pageManager = resolver.adaptTo(Packages.com.day.cq.wcm.api.PageManager);
// get containing page in /content/usergenerated
var containingPage = pageManager.getContainingPage(path);
var newPage = pageManager.create(path, containingPage.getName(), template, containingPage.getTitle());
// below code doesn't work
var jcrUtil = sling.getService(Packages.org.apache.sling.jcr.resource.JcrResourceUtil);
jcrUtil.createPath(newPage.getPath() + "/jcr:content/test", null, null, session, true);
What is the error you are getting?
Thanks for your reply! I'm not getting an explicit error, the above code just isn't creating the node like I would expect it to, so it's kinda hard to track down exactly what is going on. I am able to successfully create the new page, but I can't create the node underneath it with jcrUtil.createPath
Did you try session.save(); after creating the new page? because the API will create the page but it doesn't save to repository completely and because in next line you are trying to create another node underneath that (do the same for this too). Try it and let us know.