Code Snippets

Creating Folders to Archive Documents in Alfresco

Here is a simple way to archive documents into a folder.

All we need to do is create a rule in the root archive folder and execute this script whenever a document is moved to this folder:

var today = new Date(); var year = today.getFullYear(); var month = today.getMonth() +1; var day = today.getDate(); var yearFolder = space.childByNamePath(year); if(yearFolder == null || yearFolder == undefined) { yearFolder = space.createFolder(year); } var monthFolder = yearFolder.childByNamePath(month); if(monthFolder == null || monthFolder == undefined) { monthFolder = yearFolder.createFolder(month); } var dayFolder = monthFolder.childByNamePath(day); if(dayFolder == null || dayFolder == undefined) { dayFolder = monthFolder.createFolder(day); } document.move(dayFolder);

 

For further information, please refer to this blog post.

Resource Tags: