Home

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<aspect name=" test:counter ">
         <title>Counter</title>
         <properties>
           <property name="test:countervalue">
               <title>Counter Value</title>
               <type>d:int</type>
           </property>
         </properties>
</aspect>

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.

RenameFolderScript.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var NewDocID=1;
var prefixstring="abc-xyz-comp-";
    if(!space.hasAspect("trans:counter"))
    {
        var props1 = new Array(1);
        props1["trans:countervalue"] =1;
        space.addAspect("trans:counter",props1);
        space.save();
    }else
    {
        var LastDocID = space.properties["test:countervalue"];
        NewDocID = LastDocID + 1;
        space.properties["test:counter"] = NewDocID;
        space.save();
    }
var props = new Array(2);
props["test:counter"] =NewDocID;
props["test:transmittalno"] =prefixstring+NewDocID;
document.addAspect("test:counter",props);
document.name=document.name+NewDocID;
document.save();

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

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!

Publicités

Laisser un commentaire

Choisissez une méthode de connexion pour poster votre commentaire:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s