02-21-2018 04:24 AM
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
02-21-2018 05:56 AM
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...
02-21-2018 05:57 AM
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.
02-21-2018 06:51 AM
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.
02-21-2018 01:23 PM
It’s undefiniert because a String (noderef) has no „parent“ attribute. See Code above...
02-21-2018 11:44 PM
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();
Explore our Alfresco products with the links below. Use labels to filter content by product module.