cancel
Showing results for 
Search instead for 
Did you mean: 

Need to move a node to a parent of a search result

srowsell
Champ in-the-making
Champ in-the-making
I have a script in Share which looks like this:


var contractID=document.properties["contract:contractID"];
var results=search.luceneSearch("+PATH:\"/app:company_home/st:sites/cm:contract-management/cm:documentLibrary//*\" +TYPE:\"{duca.contracts.model}contract\"");

if (contractID!=null)
{
   for (var i=0;i<results.length;i++)
   {
      if (results.properties["contract:contractID"]==contractID)
      {
         document.move(results.parent);
         break;
      }
   }
   
}


The idea is that the user will update a property, which will trigger a rule, which will execute this script.  The search will return at least one result – the one whose contractID property matches the one of the file that was just updated – and then move the just-updated document into the same folder as the document which was found in the search.

My problem, I think, is just the syntax of the parent node.  Are there any insights better than mine?
4 REPLIES 4

zladuric
Champ on-the-rise
Champ on-the-rise
I think you need another parent in there. Ie. if you put a doc in doc.parent, it means you've placed it to where it already is. So you want to do a doc.move(doc.parent.parent);
Or did I misunderstand something?

Another thing, why don't you combine this property right into your search?

Ie. var res = search.luceneSearch(+PATH:\"/app:company_home/st:sites/cm:contract-management/cm:documentLibrary//*\" +TYPE:\"{duca.contracts.model}contract\" +@"contract:contractID\:\"contractID\"");

srowsell
Champ in-the-making
Champ in-the-making
There are two documents being considered here:  the document which is being acted upon by this rule (i.e. document) and the document found by the lucene search (i.e. results).  (Your suggestion about putting that into the search is a good one, by the way.)  I need to place document as a sibling of results, which is why I wanted to move it to results.parent.

srowsell
Champ in-the-making
Champ in-the-making
The problem has been fixed in the initial post.  It turns out that among my errors, these were causing my problems:

1.  I was using the wrong kind of rule – on file creation, rather than file update
2.  I was using parentheses instead of brackets for the properties "if" condition

Thanks for your help.

EDIT:  the query has to look more like this:

var results=search.luceneSearch("+PATH:\"/app:company_home/st:sites/cm:contract-management/cm:documentLibrary//*\" +TYPE:\"{duca.contracts.model}contract\"+@contract\\:contractID:\""+contractID+"\"");


But the suggestion was still useful.

zladuric
Champ on-the-rise
Champ on-the-rise
No problem, keep up the good work Smiley Happy