cancel
Showing results for 
Search instead for 
Did you mean: 

Sequencial Number

ltardioli
Champ in-the-making
Champ in-the-making
Hello guys,

I'm trying to create an action that when a document arrive it is duplicated and sent to another folder.
But this new folder must be unique with a sequencial number on its name.

My only problem is this sequencial number. Anyone knows how to do this?

Thanks a lot!
5 REPLIES 5

jordiv
Champ on-the-rise
Champ on-the-rise
You could count the number of folders already created there and use it as your sequential number:

var sequentialNumber = destFolder.children.length;


Cheers,
Jordi

ltardioli
Champ in-the-making
Champ in-the-making
Good idea!
Thanks!

But now I got another problem.

When a try to create a new folder with the name of the file that I put into the folder doesnt work…

Here is my script;
//I create a name
var name = document.name+"TestName";
var backupFolder = space.childByNamePath(name); //confirm if the folder with the name exists
if (backupFolder == null && space.hasPermission("CreateChildren"))
{
   backupFolder = space.createFolder(name); //Create a folder
}


But nothing happen….

jordiv
Champ on-the-rise
Champ on-the-rise
I've tried your code with the Javascript Console and it works for me.

Make sure your space variable points to the path that you want, and check the ${ALFRESCO_HOME}/tomcat/logs/catalina.out file for errors.


Cheers,
Jordi

lista
Star Contributor
Star Contributor
Check the "countable" aspect + action, it does exactly what you need.

scouil
Star Contributor
Star Contributor
I don't think the ".children.length" is a good idea. If you create 2 folders it will name them "1" and "2".
Then if you delete folder "1" and try to recreate a new folder, won't it try to name it "2" which already exists?

I personally use the database ID that each node has:


var prefix = "Folder";

var newFolder = companyhome.childByNamePath("my/Path").createNode(null, "cm:folder");
var unique = "_" + newFolder.properties["sys:node-dbid"];

newFolder.properties.name = prefix + unique;
newFolder.save();