Script to Generate Serial Number for Child Folders in Alfresco

Recently I have come across one of the requirement where customer have particular name pattern for all spaces (folders). So, irrespective of whatever name given by creator alfresco should generate one number based on pattern and should apply that name to folder.

One example of such pattern is like “abc-xyz-comp-<serialno>”

Where serialno à refers to Serial number generated. We need to maintain one counter where each of these folders needs to give incremental number like “abc-xyz-comp-1”, “abc-xyz-comp-2”….. And so on.

Now question is how to achieve this?

For this first requirement we need to maintain one counter which keep track of last serial number.

Here we are creating one counter aspect which keeps track of this counter.

<aspect name=" test:counter ">



           <property name="test:countervalue">

               <title>Counter Value</title>





Now apply this aspect on parent folder under which you want to apply that pattern.

Next step would be create script which will read this counter value, create new name of new folder, rename new folder according to pattern name, Increment counter value.


 var NewDocID=1;
var prefixstring="abc-xyz-comp-";
        var props1 = new Array(1);
        props1["trans:countervalue"] =1;
        var LastDocID =["test:countervalue"];
        NewDocID = LastDocID + 1;["test:counter"] = NewDocID;;
var props = new Array(2);
props["test:counter"] =NewDocID;
props["test:transmittalno"] =prefixstring+NewDocID;

Now upload this script under Company Home>Data Dictionary>Scripts from alfresco user interface.

Create a Rule on Parent space with following set of parameters. This rule will be executed whenever new space is being created inside it. This rule will invoke RenameFolder.js script and rename folder according to our require pattern.

Rule to rename Folder with pattern

Rule to rename Folder with pattern

Summary: This is one more great use of alfresco javascript which we had discussed earlier in this post. In this post I have used Space and Folder interchangeably both of them are same in context to alfresco.

Looking for quality Alfresco Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight


I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

6 Comments on Script to Generate Serial Number for Child Folders in Alfresco

  1. Better yet, you could use one of the OOTB aspects.

    The cm:countable aspect is defined like this:




  2. Trying again to fix the code:

    <aspect name="cm:countable"> &lt;title&gt;Countable&lt;/title&gt; <properties> <property name="cm:hits"> <type>d:int</type> </property> <property name="cm:counter"> <type>d:int</type> </property> </properties> </aspect>

  3. sangeetha says:

    How many rules can create into a single folder in Alfresco?

Leave a Reply

Your email address will not be published. Required fields are marked *