AnsweredAssumed Answered

[Solved] Alfresco Javascript and counters.

Question asked by red15 on Jan 10, 2007
Latest reply on Jan 10, 2007 by red15
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);



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.)