cancel
Showing results for 
Search instead for 
Did you mean: 

how to find documentLibrary using childByNamePath

gerryr
Champ in-the-making
Champ in-the-making
I'm trying to populate the documentLibrary section of a new site using some javascript like this:

<javascript>sourceNode.copy(document.childByNamePath("documentLibrary"), true);</javascript>

where document is the new site.

This statement always errors though giving this error:
Destination Node is a mandatory parameter


but yet when I copy to the document root it works like this:

<javascript>sourceNode.copy(document, true);</javascript>

Why cannot it find the documentLibrary node?

UPDATE:
More info:  I'm triggering this script from a rule on the Sites directory.  I'm wondering if there is a race condition where the site gets created under Sites but does not yet have it's documentLibrary node.  That would cause what I'm seeing if this can happen.

UPDATE2:
Yes something like this is happening because document.children is empty.
If I don't fire the rule the site gets created just fine and has a documentLibrary.
Why doesn't the site have all its children such as the documentLibrary when it first gets placed under Sites?




2 REPLIES 2

jpotts
World-Class Innovator
World-Class Innovator
Because containers for tools don't get created until the tool is used the first time. It is the same reason there is not a wiki, discussion, or calendar folder when the site gets created.

The workaround is simple though. Modify your script to check to see if the documentLibrary node exists. If it does not, just create it. You can look up an existing documentLibrary folder in the node browser to make sure you get the type and name exactly right.

Jeff

gerryr
Champ in-the-making
Champ in-the-making
Thanks, Jeff.

I'll create the necessary nodes in my script.