Use Alfresco folder rules to perform admin tasks

Introduction

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.

Choose 'Manage Rules' as above to create rules for a folder

‘Manage Rules’  to create rules for a 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.

Example rule to set all JPEG files to type 'fieldphoto'

Rule to set all JPEG files under the folder to type ‘fieldphoto’

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.

Run rules for the folder and sub-folders

Run rules for the folder and sub-folders

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.

folder_rules_enabled

Rules for the Fieldobs folder – rules 1, 2, 3 and 5 are 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.

Alfresco scripts folder

All scripts stored in the ‘Scripts’ folder can be run within folder rules

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!";

Further information

My follow-up blog – Using javascript console to create a folder rule script

The Alfresco Wiki (although officially superseded) has good Javascript API examples – https://wiki.alfresco.com/wiki/4.0_JavaScript_API#Root_Scope_Objects

Alfresco JavaScript API reference – http://docs.alfresco.com/community/references/API-JS-Scripting-API.html

Note that the javascript in the folder rules runs on the Alfresco server and the API that is used to access properties of documents, photos, etc. is sometimes referred to as the  ‘Alfresco Repository JavaScript API’.  Do not confuse this with the ‘Alfresco Share JavaScript API’ which runs on the client – ie. in the user’s browser.  The following section in the official docs explains the various programming interfaces to Alfresco – http://docs.alfresco.com/community/concepts/API-intro.html

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).

2 thoughts on “Use Alfresco folder rules to perform admin tasks

  1. Pingback: WebDAV, Cyberduck – upload bulk files into Alfresco | Geology FOSS Blog

  2. Pingback: Using javascript console to create a folder rule script in Alfresco | Geology FOSS Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s