cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript to create a child node

mrey
Champ in-the-making
Champ in-the-making
Hi all

Have a quick question please. I need to create a JS script for Alfresco that would look for a space and if found, will create in it a child space with a given name.

I know to look for the parent Space I can use this code

var ParentSpace = space.childByNamePath("parentSpaceName");

So then to create the child node I have created this

if (ParentSpace != null && space.hasPermission("CreateChildren"))
{
   ChildSpace = space.createFolder("ChildName");
}

but with this what I get is the "child space" to be created at the same level than the Parent Space, not inside the Parent Space

Any Suggestions on how I can "tell" the code to create the child space inside the Parent Space?

Thanks a lot guys Smiley Very Happy
1 REPLY 1

jpotts
World-Class Innovator
World-Class Innovator
The "space" variable will always be populated with the space the script is currently running against. Similar with "document" although you aren't using that in this example.

So instead of space.createFolder() you need to do ParentSpace.createFolder(). Also, in your hasPermission() check, you want to run that on the ParentFolder, not the current space.

Jeff