cancel
Showing results for 
Search instead for 
Did you mean: 

Script to copy documents to a relevant folder

anuradha1
Star Contributor
Star Contributor

Hi, I am using Alfresco Community 5.2 and i need to create a script to copy document to a relevant folder. 

copy-to-rel-folder.js
 

var createdDate = document.properties["cm:created"];

var dd = createdDate.getDate();
var mm = createdDate.getMonth()+1; //January is 0!

var yyyy = createdDate.getFullYear();
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
var today = dd + "-" + mm + "-" + yyyy;

var objDestFolder = companyhome.childByNamePath("Shared/SECRETARY/COMMISSION_MEETINGS/" + today);
document.copy(objDestFolder);

Ex: today = 20-03-2018 but I am having folders named 10-03-2018 ,18-04-2018 , 09-03-2017. I need to copy the document into 10-03-2018 folder. I need to select the folder using LIKE mm + "-" + "-" + "yyyy" (not considering the date).

Please help me.

Thank you.

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

Simply get the name path until the "COMMISSION_MEETINGS" folder and then iterate over iters chidlren, checking the folder names against your pattern using endsWith / regex checks. Or you may perform an FTS query using the "search" root scope object looking into the path and doing a wildcard match on the folder names.

View answer in original post

6 REPLIES 6

afaust
Legendary Innovator
Legendary Innovator

Simply get the name path until the "COMMISSION_MEETINGS" folder and then iterate over iters chidlren, checking the folder names against your pattern using endsWith / regex checks. Or you may perform an FTS query using the "search" root scope object looking into the path and doing a wildcard match on the folder names.

anuradha1
Star Contributor
Star Contributor

Thanks Axel.
Could you please give me a sample code how to do it. I have no idea about how to change my code to achieve this. 

afaust
Legendary Innovator
Legendary Innovator

How did you write the code you already have? It shouldn't need a sample to make two or three small adjustments to the code if you have written it yourself. I recommend you make yourself familiar with the ScriptNode API if you are unsure about which properties / functions to call. Specifically you should only need to use the childFileFolders() function and the name property to deal with the contents of the COMMISSION_MEETINGS folder and filter by name..

anuradha1
Star Contributor
Star Contributor

I'll try this way & will inform if i success in this.
Thank you.

Getting started

Explore our Alfresco products with the links below. Use labels to filter content by product module.