cancel
Showing results for 
Search instead for 
Did you mean: 

Question about workflow: Copy file to new folder

strecki
Champ in-the-making
Champ in-the-making
I'd like to have a workflow, that when a certain file is uploaded:

1. Converts that file to a PDF
2. Checks if the original folder of the file already exists
2.1 If yes, copy the PDF to the folder
2.3 If no, create the folder and then copy

For example: /folder1/testfile.doc is uploaded

Then the script should check for /folder1/, create it, if necessary, and copy the converted file to
e.g /companyhome/folder1/testfile.pdf

Is it possible to get the original folder structure from the uploaded file (on which then the rule is used), because when the file is already in Alfresco, it it not possible.

A script, which creates a previously specified folder is easily written, but not a dynamic folder.

Any help is much appreciated.

&EDIT: I'm now using part of the filename as a new folder, that works and no more help is needed.
3 REPLIES 3

bchevallereau
Champ in-the-making
Champ in-the-making
Hi,

Why you want to use a workflow, a simple JS rule can do that.

Ben

thomas_x
Champ on-the-rise
Champ on-the-rise
can you please describe in a short way how to do this ?
It would be great if you send a short example

strecki
Champ in-the-making
Champ in-the-making
This is my solution:


The first part creates a new folder for outputs (if none exists).

var subFolderName = "Output";                     
var subFolder = companyhome.childByNamePath(subFolderName);

if (subFolder == undefined || !subFolder.isContainer)
{
   subFolder = companyhome.createFolder(subFolderName);
}

Now I get the first part of the filename (in my case until "_" is found).

var name = document.name.toString();                
var id = name.substring(0,name.lastIndexOf("_"));      

Now to create a new folder with the first part of the filename in "Output".

var destFolder = subFolder.childByNamePath(id);         

if (destFolder == undefined || !destFolder.isContainer)   
{
   destFolder = subFolder.createFolder(id);
}

… and finally convert the file to PDF and move to the new destination:

var type = "application/pdf";
var newDocument = document.transformDocument(type);      
newDocument.move(destFolder);

I saved this script as moveAndConvert.js and execute it when certain files are uploaded.

I hope this helps.