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 "> <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
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.
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!
Better yet, you could use one of the OOTB aspects.
The cm:countable aspect is defined like this:
Countable
d:int
d:int
Yes, this too is possible but this will be helpful if you have conditional increment.
Trying again to fix the code:
<aspect name="cm:countable"> <title>Countable</title> <properties> <property name="cm:hits"> <type>d:int</type> </property> <property name="cm:counter"> <type>d:int</type> </property> </properties> </aspect>
What you are trying to fix? Please avoid to paste code directly in comment as much as possible
How many rules can create into a single folder in Alfresco?
There is no such limit on number of rule as far as I know.