cancel
Showing results for 
Search instead for 
Did you mean: 

[Solved] Alfresco Javascript and counters.

red15
Champ in-the-making
Champ in-the-making
Hi all,

I am not sure if this is the correct place to post this question but I couldn't find anything more specific to writing scripts.

I have this piece of script I wrote. Without further delay here it is :


var recordFile = companyhome.childByNamePath("counter.txt");
if ( recordFile == null ) {
   recordFile = companyhome.createFile("counter.txt");
   recordFile.content = "1";
}

if ( recordFile != null ) {
  var counter = recordFile.content;
  counter = eval(counter+1);
}

var rootbrief = companyhome.childByNamePath("Briefwisseling");

rootbrief.createFolder("Dossier "+counter);
var dossierfolder = rootbrief.childByNamePath("Dossier "+counter);

dossierfolder.createFolder("Aanvraag");
dossierfolder.createFolder("Antwoord");

document.move(dossierfolder.childByNamePath("Aanvraag"));

recordFile.content = counter;

logger.log("Created dossier "+counter);

Fairly simple, any file dropped in the Space that executes this script creates some subdirectories and moves the file into this structure.

I also use a counter file which contains value 1 at start. So I first tried to increment the value by using

  var counter = recordFile.content;
  counter = counter+1;

But what I actually get then is not "2" but "11".
So I added eval() brackets around the counter addition. But no joy… stil get 11 then 111 and so forth.

So my question is how do I add increase this value I get from the content in my recordFile using Alfresco Javascript.

(Also if anyone knows a better way to keep track of some sort of counter please tell me.)
1 REPLY 1

red15
Champ in-the-making
Champ in-the-making
Ok I guess I was a bit early on the posting.

This does the trick just fine :

  var counter = recordFile.content;
  counter++;

Good ol' c++ Smiley Happy

The question whether there is a better way to keep track of a number is still open for anyone interested.