site-rules-js-stUsing Alfresco One, it is very simple to extend the document structure that is deployed upon a Site creation. An automatic structure deployment can allow for a group of rules, folder structure and documents and other functionalities to be created within a site, when the site is instantiated. The nice thing about this functionality, is that it can be implemented from the GUI with the use of Rules, Scripts and Space Templates.

To implement this functionality, first we will define our  folder structure under /Data Dictionary/Space Templates. The folder structure that we define can be simple structures, or smart structures with additional rules and actions. For the purposes of this project, we’ll use the example template for a Software Engineering Project, as depicted in the following photo.Space Templates The Software Engineering Project template is provided by the default installation of Alfresco, and contains a subdirectory structure for maintaing artifacts of a typical Software Engineering project.

Next we will define the Javascript that will provide the routines for implementing the template import into the Site when it is created.

This script will be defined under /Data Dictionary/Scripts/. The name of the javascript must end in .js, and the mimetype of the script’s properties should be set to “Javascript.” In our example we will define a script as follows:

Import Software Engineering Space Template.js

var mQuery = {
 query: "select * from cmis:folder where contains " +
 "('PATH:"/app:company_home/app:dictionary/app:space_templates/*"') " +
 "and cmis:name='Software Engineering Project'",
 language: "cmis-alfresco"

var results = search.query(mQuery);

//copy the template into our Document Folder
try {
var copy = results[0].copy(document,true);
} catch (e) {

In the last step oAlfresco » Folder Rulesf our configurations, we will add a rule to the /Sites folder, where all sites in the system are created. This rule will listen for onCreate events within the directory, and execute whenever a folder with the Component Id property of the Site Container Aspect is set to documentLibrary. Which is one of the unique properties that identifies the Document Library within a site. This attribute can be selected by selecting “Show More” of the “If all criteria are met” section of the Rules definition form.
Alfresco_»_Folder_Rules 2

Selecting this option will open a modal window with a list of categories to choose from. In that list, choose “Aspects” on the left, and followed by “Site Container.” When Site Container is selected, you will have the option to select the Component Id property of the aspect to utilize in your rules criteria.

Once the Component Id is selected, set the validator expression to say “Equals” and fill in “documentLibrary” for the value. This rule will now execute when a folder with the Aspect of SiteContainer and Container Id property set to “documentLibrary.”

The last step of the rules definition form would be to add an action to perform when the rule is triggered. In this case, we’ll select the “Execute Script” as our action, followed by select the Javascript Import Software Engineering Space Template.js that we previously added.

Finally, select the checkbox “Rule applies to subfolders” and hit “Create.”

Our configurations are now completed, and we can test it by creating a new site and validating that our templates were copied.



Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: