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
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...
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.
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.
It’s undefiniert because a String (noderef) has no „parent“ attribute. See Code above...
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();
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.