03-12-2018 02:38 AM
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.
03-12-2018 05:41 AM
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.
03-12-2018 05:41 AM
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.
03-12-2018 09:31 PM
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.
03-13-2018 10:12 AM
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..
03-13-2018 09:41 PM
I'll try this way & will inform if i success in this.
Thank you.
Explore our Alfresco products with the links below. Use labels to filter content by product module.