cancel
Showing results for 
Search instead for 
Did you mean: 

Rule to dynamically create month- and day-folders

thk
Champ on-the-rise
Champ on-the-rise
Hello,

im using Alfresco 2.1 and I want to create a rule which whenever a file arrives first creates a folder with the creation-day in the name and then moves the file in this folder. When the folder for this day already exists the rule should only move all files with this creationday in it. If a new month begins all day folders should be moved in a new created month-folder.

How can I implement this with Alfresco? Simple solution preferred.

Thanks for Help
3 REPLIES 3

kbonnet
Champ in-the-making
Champ in-the-making
Hi Thk,

At a client i had a similar requirement. I was able to implement it via a content rule and a small, simple javascript.

Hope this helps.

Koen

thk
Champ on-the-rise
Champ on-the-rise
Hi,

thanks for reply. Unfortunately i'm not familiar with javascript. Can you send me your script as an example?

Best Regards
Thomas

dgenard
Champ on-the-rise
Champ on-the-rise
Hi, here is a sample script doing just this :


// Move document to YYYY/MM/DD structure
// First, find or create target folder
var current = document.properties["cm:created"];
var year = current.getFullYear();
var month = current.getMonth() + 1;
var day = current.getDate();

var yearSpace = space.childByNamePath(year);
if (yearSpace == null) {
   yearSpace = space.createFolder(year);
}
var monthSpace = yearSpace.childByNamePath(month);
if (monthSpace == null) {
    monthSpace = yearSpace.createFolder(month);
}
var daySpace = monthSpace.childByNamePath(day);
if (daySpace == null) {
   daySpace = monthSpace.createFolder(day);
}

// Then move document
document.move(daySpace);
Trigger this script with an inbound rule on a given space, and it will automatically create a year/month/date structure in this space.

Hope this helps,
Denis