Folder rules are ordinarily used to initiate tasks when files are created or updated, but they can also be a convenient way to manage admin or migration tasks. For example, you might need to perform bulk changes to properties of files.
Create a folder rule
To create a rule for a folder, choose ‘Manage Rules’ for the folder.
Example folder rule
The following is a folder rule that I used after migrating data into Alfresco using Cyberduck and WebDAV. Choose ‘Items are updated’ for a rule that you want to run immediately.
Note that if you want to process files in subfolders, you will need to choose ‘Run rules for this folder and its subfolders’ – even though you have ticked ‘Rule applies to subfolders’ above.
Note that when you click ‘Run Rules’, ALL the enabled rules for the folder are run, so you need to disable all rules that you don’t want to run. In the example below, only the ‘Create thumbnails’ rule will run, as the other rules have been disabled.
Scripts – extending the power of folder rules
There are many types of tasks that you can choose when defining a folder rule, but you can extend these choices even further by creating scripts in the ‘Scripts’ folder under the ‘Data Dictionary’ folder. All of the scripts in this folder that have the extension ‘.js’ are listed when you choose ‘Execute script’ in your folder rule.
The are many useful sample scripts in this folder. ‘example test script.js.sample’ is a good script to start with – it shows ways of accessing the properties of each file/subfolder – for example …
// test accessing current document properties and modifying them var docname = document.name.substring(0, document.name.lastIndexOf('.')); document.properties.name = "12345 " + document.properties.name; document.save(); // modify the parent space name space.name = space.name + " 1"; space.save(); // test accessing document content var content = document.content; // update the content by appending a string document.content = content + "\r\nHere is another line added from a script!";
Order of the Bee – an independent organisation of the Alfresco community. Web-site includes good technical and non-technical posts and other information, focussed mainly on Alfresco Community Edition (CE).