cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript to move file into folder

dbzmkl
Champ in-the-making
Champ in-the-making
Hi All,

I have recently deployed alfresco(5.1.0 community edition) to manage our internal documents and it works great.

I would like to implement a hot folder where once a file is uploaded to the folder it is moved to a folder with the same title as the file.


What I mean is if I upload a file with a title KD/IT/SOP/1 it should be moved to folder with the title KD/IT/SOP

I have been researching and it seems doing a rule that calls javascript would be my best option. However, I'm pretty new to javascript and wouldn't know where to start. Any pointers would by highly appreciated.
3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator
<a href="http://docs.alfresco.com/5.1/references/API-JS-move.html">Here</a> is the doc on the "move" method.

In your folder rule you'll automatically get a variable named document. So if you can use other calls to get a handle to the folder node you want to move it to, you can call that move function.

Looks like you'll also want to create a new folder to place that document in. So you'll want to call createFolder on the parent to create the new folder before you call move on the document.

Jeff

cibex
Champ in-the-making
Champ in-the-making
var strDestFolder ="sites/KD/IT/SOP/";
var objDestFolder = companyhome.childByNamePath(strDestFolder);
document.move(objDestFolder);

if the destination folder is not the same you may generate a path variable from eg the node (document) name. won´t work if the destination folder does not exist or you don´t have correct permissions (needing delete in the source path).

kr
Josef

cibex
Champ in-the-making
Champ in-the-making
var strDestFolder ="sites/KD/IT/SOP/";
var objDestFolder = companyhome.childByNamePath(strDestFolder);
document.move(objDestFolder);

if the destination folder is not the same you may generate a path variable from eg the node (document) name. won´t work if the destination folder does not exist or you don´t have correct permissions (needing delete in the source path).

kr
Josef