cancel
Showing results for 
Search instead for 
Did you mean: 

search.findNode() and Associations

ghernando
Champ in-the-making
Champ in-the-making
I want to be able to find the working copy node associated with a checkedout document.
I'm using Javascript and have a ScriptNode for the original document found by using search.findNode(nodeRef).

When I use the node browser I see that the aspect cm:checkoutOut is set on the original node and that there is an association {http://www.alfresco.org/model/content/1.0}workingcopylink
also set.

In Javascript I'm able to check node.hasAspect("cm:checkoutOut") and it correctly says that it is set.
But I'm unable to get the workingcopy. 

I tried
node.assocs["cm:workingcopylink"][0]
But it gives an error saying that it is null.

How can I get the working copy?
5 REPLIES 5

lista
Star Contributor
Star Contributor
I don't remember ATM how associations are set, but you can check for node.sourceAssocs just like you check for node.assocs. This is a wild guess for now, but it should be a breeze to try.

ghernando
Champ in-the-making
Champ in-the-making
>>  node.sourceAssocs just like you check for node.assocs
No.  Neither of these contains it.

muralidharand
Star Contributor
Star Contributor
Hi,
I used the below code to cancel the working copy of all the documents. Please have a look at this and this may  help you.


var results = search.selectNodes("workspace://SpacesStore","descendant::*[hasAspect('cm:workingcopy')]");
logger.info("Total rows" + results.length);
for(var i=0;i<results.length;i++)
{
var node  = results;
var nodename = node.name;
node.cancelCheckout();
}


http://mralfresco.blogspot.in/2012/11/remove-working-copy-documents-in.html

Murali – thanks for responding, but that's not what I'm looking for.  You are searching and finding the working copies for all documents.
I want to be able to find the working copy associated with one particular document.

muralidharand
Star Contributor
Star Contributor
Hi,

Can you please try this and post your search.findNode() query also. So that, i will simulate the exact one.

I'm not sure, how much it is correct,but I got the working copy link.

 
logger.log("Original document " + document.assocs["cm:original"][0].nodeRef);
logger.log("workingcopylink document " + document.assocs["cm:original"][0].assocs["cm:workingcopylink"][0].nodeRef);


Hope this helps you.