not able to fetch the parent of a node in share side js

cancel
Showing results for 
Search instead for 
Did you mean: 
ayushi_agrahari
Active Member II

not able to fetch the parent of a node in share side js

I am trying to find the parent of a node in node-header.get.js by doing the following;

   var str = model.nodeRef;
   logger.log("childnoderef"+str);
   var parentNodeRef = str.parent;
   logger.log("parentNodeRef"+parentNodeRef);

 but parentNodeRef is coming undefined

On some googling,I have found out that parent property is not available in share-side js(node-header.get.js)

can anyone tell me any way to find the parent of a node in share side js

5 Replies
mehe
Senior Member II

Re: not able to fetch the parent of a node in share side js

You need the node Object to use X.parent, but you only have the nodeRef

var node=search.findNode(str);   //now you have the node object

var parentNode=node.parent;

var parentNodeRef=parentNode.nodeRef;

you could do this in a "one-liner" if you like...

krutik_jayswal
Senior Member II

Re: not able to fetch the parent of a node in share side js

There is always been confusion in this I guess.The script which you are trying to override is inside the share server side script.Its some thing like , you are trying to use repository javascript api inside the share javascript file.

For this you need to call repository webscript and use it.

ayushi_agrahari
Active Member II

Re: not able to fetch the parent of a node in share side js

thanks krutik,now I understand why it is giving undefined.

now can you tell me if there is any out of the webscript that gives the parent of a node so that I can call that webscript or should I need to make a custom webscript.

mehe
Senior Member II

Re: not able to fetch the parent of a node in share side js

It’s undefiniert because a String (noderef) has no „parent“ attribute. See Code above...

krutik_jayswal
Senior Member II

Re: not able to fetch the parent of a node in share side js

Elaborating more on this,

node-header.get.js file is created inside the alfresco share.So using repository api's will not be possible over there.search object is available on repository side and not on alfresco share  so that will also not work in this file.Below link contains the root objects which are available in alfresco share.

Surf root objects | Alfresco Documentation 

There is no existing webscript using which you can get the parent of a node, you need to make your own.Below is the code for repository controller script.for getting the parent of a node.Make sure you create this on repository side and not in alfresco share.

function main() {      var nodeRefArg= args["nodeRef"];      var node = search.findNode(nodeRefArg);      if (node.exists()) {          model.nodeRefModel = node.getParent().getNodeRef().toString();      } else {           model.nodeRefModel = "N/A";      } }  main();