cancel
Showing results for 
Search instead for 
Did you mean: 

Script to move a file to folder dynamically

renato_fritola
Confirmed Champ
Confirmed Champ

I need a script that moves a file to a folder dynamically. The URL of the folder will be registered in a folder's parent property of the file.

The script should take this parameter from the path to where the file should be moved and move it to it. Can someone give me an example of how to do this?

Thanks

1 ACCEPTED ANSWER

shyam_ghodasra
Confirmed Champ
Confirmed Champ

Hi Renato Fritola,

if you running script as the rule then you will get the document object directly..

var parentNode= document.parent;// getting the parent of the docuemnt  
var movePath = parentNode.properties["cm:movePath"] //get the path where you want to move from the property
// Path should be some thing like this "sites/test/documentLibrary/testFolder" if not then convert something like this..
var destination =companyhome.childByNamePath(movePath);
document.move(destination);‍‍‍‍‍‍‍‍‍‍‍‍

Plz look in to this bellow links for all the methods and root object you will get in to javascript..

1)Root objects | Alfresco Documentation 

2)ScriptNode API | Alfresco Documentation 

3)JavaScript API Cookbook  

Thanks 
Shyam Ghodasra

View answer in original post

2 REPLIES 2

shyam_ghodasra
Confirmed Champ
Confirmed Champ

Hi Renato Fritola,

if you running script as the rule then you will get the document object directly..

var parentNode= document.parent;// getting the parent of the docuemnt  
var movePath = parentNode.properties["cm:movePath"] //get the path where you want to move from the property
// Path should be some thing like this "sites/test/documentLibrary/testFolder" if not then convert something like this..
var destination =companyhome.childByNamePath(movePath);
document.move(destination);‍‍‍‍‍‍‍‍‍‍‍‍

Plz look in to this bellow links for all the methods and root object you will get in to javascript..

1)Root objects | Alfresco Documentation 

2)ScriptNode API | Alfresco Documentation 

3)JavaScript API Cookbook  

Thanks 
Shyam Ghodasra

Worked perfectly!

Thank you.