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.
Solved! Go to Solution.
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.
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.
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.
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..
just change the way you filled your "today" variable
I'll try this way & will inform if i success in this.
Thank you.
I have achieved that task using childFileFolders() method.
Thanks all for helping me.
My JS code is below, in case if someone needs.
//Get document created date
var createdDate = document.properties["cm:created"];
//Get date, month & year seperately from the createdDate
var dd = createdDate.getDate();
var mm = createdDate.getMonth()+1; //January is 0!
var yyyy = createdDate.getFullYear();
//Date & month formatting
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
//Get access to the parent folder
var objDestFolder = companyhome.childByNamePath("Shared/public");
//Get all childrens in the parent folder into nodes array
var nodes = objDestFolder.childFileFolders();
var x = nodes.length;
nodes.sort(function(a, b){return a - b});
//Chack whether folder name(date) > created date
for (i = 0; i < x; i++) {
var ch = objDestFolder.children[i].name;
var ch1 = objDestFolder.children[i].properties["cm:title"];
var res = ch1.split(": ");
var fDate = res[1];
var res1 = fDate.split("/");
var fDD = res1[0];
var fMM = res1[1];
var fYYYY = res1[2];
if(yyyy == fYYYY)
{
if(mm == fMM)
{
if(dd <= fDD)
{
//Document move to the relevant folder
var folderDes = companyhome.childByNamePath("Shared/public/" + ch);
document.move(folderDes);
}
}
}
}
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.