Script to move a file to folder dynamically

cancel
Showing results for 
Search instead for 
Did you mean: 
renato_fritola
Active Member II

Script to move a file to folder dynamically

Jump to solution

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 Solution

Accepted Solutions
shyam_ghodasra
Active Member II

Re: Script to move a file to folder dynamically

Jump to solution

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 solution in original post

2 Replies
shyam_ghodasra
Active Member II

Re: Script to move a file to folder dynamically

Jump to solution

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

renato_fritola
Active Member II

Re: Script to move a file to folder dynamically

Jump to solution

Worked perfectly!

Thank you.