cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting and changing nodes parent folders using JS

ado
Champ in-the-making
Champ in-the-making
Dear experts,

I am currently trying to write a script that would be called by SAP with three parameters, date, document and store. The JS will then create a store if the specified store does not exists, within this store there would be a monthly folder that if it does not exists will be created and then within this monthly folder, I would place my document specified by the document parameter.

So far the entire structure for the store/date folder creation and selection is working perfectly. its with moving the files that I am having some problems.

All the files are stored in a staging store where they can be selected.

I have been able to create a lucene search query to find the node according to the document number specified within the staging store. Is there a way I can then use this selected node and move it into the correct date folder?

Can one access the folderPath property of the node and just change it to be a child of the date node?
Is there another method of moving the files into the correct store?
Is it possible to use the document DOM object within a script to do this? If indeed how do you go about specifying the document object?

Thank you for any help regarding this, I truly am lost.

Best regards

ADO
8 REPLIES 8

ado
Champ in-the-making
Champ in-the-making
Hi

here is my JS thus far, problem area specified and describe within stars:

var resultString = "Action failed",
resultCode = false;
resultString = "Could not create space";

         var doc = args.q,
            store = args.s,
            time = args.t;
   

         var nodeNew;
        
         if ((doc== null) || (doc == ""))
         {
            resultString = "document must be specified";
         }
         else
         {
           
            var nodeParent = roothome.childByNamePath("Company Home/Sites/ITD");
         var testCompany = roothome.childByNamePath("Company Home/Sites/ITD/" + store);
         if (testCompany == null)
         {
         var nodenewstore;
         nodenewstore =    nodeParent.createFolder(store);
         nodenewstore.properties["cm:title"] = store;
                        nodenewstore.properties["cm:description"] = "storage space for company specific files";
                        nodenewstore.properties["app:icon"] = "space-icon-default";
                        nodenewstore.save();
         resultString = "created store site";
         resultCode = true;
         }
         
           nodeParent = roothome.childByNamePath("Company Home/Sites/ITD/" + store);
         var testMonth = roothome.childByNamePath("Company Home/Sites/ITD/" + store + "/" + time);
            if (testMonth == null)
            {
               var nodenewmonth;
               nodenewmonth =    nodeParent.createFolder(time);
               nodenewmonth.properties["cm:title"] = time;
                                  nodenewmonth.properties["cm:description"] = "Monthly storage for company specific files";
                            nodenewmonth.properties["app:icon"] = "space-icon-default";
                                  nodenewmonth.save();
               resultString = "Created month site";
               resultCode = true;
            }
            else
            {
               resultString = "Already exists, would then move files";
               resultCode = false;
            }
          }
            
   
      if (doc == undefined || doc.length == 0)
                        {
                   model.returnCode = 1;
                   model.message = "Document name was not provided.";
                        }
                  else
                        {
   
                  path = '+PATH:"/app:company_home/st:sites/cm:ITD//*"';
                  file = '+@\\{http\\://www.alfresco.org/model/content/1.0\\}name:' + doc + '*';
                  mime = '+@\\{http\\://www.alfresco.org/model/content/1.0\\}content.mimetype:image/jpeg';
                  querie = path + " " + file + " " + mime;

                   var nodes = search.luceneSearch(querie);
                   if (nodes == null || nodes.length == 0 || nodes == undefined)
                   {
                      resultString = "File does not exist"
                   }
                   else
                   {
                     
                     resultString = nodes.name
                                          
                     var stagingFolder = roothome.childByNamePath("/Company Home/Data Dictionary/Sites/ITD/documentLibrary/Stage");
                     var placeInto = roothome.childByNamePath("Company Home/Sites/ITD/" + store + "/" + time + "/");   
                     var fullPathStr = "/Company Home/Sites/ITD/" + store + "/" + time + "/"

                        if(stagingFolder != null)
                           {

//                                                    *****************************************************************************************************************************
//                                 move document witin folder/node stagingFolder with name specified in doc, into folder/node placeInto
//                                                   *****************************************************************************************************************************

                           }
                     }      
         
                }   
    

  
model.resultString = resultString;
model.resultCode = resultCode;

mrogers
Star Contributor
Star Contributor
http://wiki.alfresco.com/wiki/3.4_JavaScript_API#ScriptNode_API

there's a 'move' method.    Give it the new parent node.

ado
Champ in-the-making
Champ in-the-making
http://wiki.alfresco.com/wiki/3.4_JavaScript_API#ScriptNode_API

there's a 'move' method.    Give it the new parent node.

Hi,

will using the node selected by the Lucene search be able to be moved? Or would I be required to select the node by other means?

zaizi
Champ in-the-making
Champ in-the-making
Yes. The node from lucene search can be moved.

ado
Champ in-the-making
Champ in-the-making
Hi experts

if I use this move method it gives a cannot find function error and ultimately does not move the actual node to the new parent. Any idea's how to solve this??

This is how I search for the document. doc is the document number passed by Post.

path = '+PATH:"/app:company_home/st:sites/cm:ITD//*"';
                  file = '+@\\{http\\://www.alfresco.org/model/content/1.0\\}name:' + doc + '*';
                  mime = '+@\\{http\\://www.alfresco.org/model/content/1.0\\}content.mimetype:image/jpeg';
                  querie = path + " " + file + " " + mime;

                   var nodes = search.luceneSearch(querie);
                   if (nodes == null || nodes.length == 0 || nodes == undefined)
                   {
                      resultString = "File does not exist";
                   }
                   else
                   {
                     
                                                               
                     var stagingFolder = roothome.childByNamePath("/Company Home/Data Dictionary/Sites/ITD/documentLibrary/Stage");
                     var placeInto = roothome.childByNamePath("Company Home/Sites/ITD/documentLibrary/" + store + "/" + time + "/");   
                     
                           
                              nodes.move(placeInto);
                              nodes.save();
                              resultString = "Move successful";


                     }      



I get the following error when trying to use the move method.

Message:   05283325 Wrapped Exception (with status template): 05283324 Failed to execute script '/sortDoc.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': 05283323 TypeError: Cannot find function move. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/sortDoc.get.js#84)
   
Exception:   org.mozilla.javascript.EcmaError - TypeError: Cannot find function move. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/sortDoc.get.js#84)

Thanks in advance

ADO

ado
Champ in-the-making
Champ in-the-making
Hi

I could have an incomplete understanding of how to apply this move function. The function requires  ScriptNode.move(newParent).

Now can you apply the move method to the selected node obtained from the lucene search or do you need to set the selected node equal to the document object/scriptNode?

1.How do you do this?

Would you assign the document object your selected node or do you need to checkout the node, causing it to be set as the document scriptnode?

Even when using the document.move() instead of nodes.move() the function can still not be found?

It might be that I have a complete misunderstanding of how these methods are implemented. Apologies for my lack of knowledge, this is my first time working on Alfresco or using JavaScript so I'm still trying to grasp it all.

Thank you in advance

ADO

lista
Star Contributor
Star Contributor
Try using "nodes[0].move(placeInto);" instead of "nodes.move(placeInto);" and see if it helps.

Cheers,
Lista.

ado
Champ in-the-making
Champ in-the-making
Try using "nodes[0].move(placeInto);" instead of "nodes.move(placeInto);" and see if it helps.

Cheers,
Lista.

Lista if I could award you 10 0000 points I would.Thank you very much, it worked. Can't believe I have been sitting with this problem for nearly a month and the "[0]" is all I needed.

Thank you once again,

best regards

ADO