@For Loop for Creating Documents?

varAI := @dblookup on 2,000 docs from db2

REM{ Code run on db1 via action button: };

@For(n := 1;

n <= @Elements(varAI) ;

n := n + 1;

@Command([Compose];“IR”) ;

@UpdateFormulaContext ;

FIELD IRAI := varAI[n] ;

@If(@Command([FileSave]);@Command([FileCloseWindow]);“”)

);

What I’m doing with this is for every document in database 2 I’m creating new documents in database 1 and populating a field in the new document from the dblookup in database 2. Why does the above code keep creating documents before saving & closing the current document? Everything is returning the proper values but as you could imagine once the document count in db2 really gets up there it bombs because of all the document windows open in db1 at the same time while its creating them. When it works (only if I lower the document count in db2) it creates all the documents, sets the field values then saves/closes them all in that order? What it should do (or at least what Im trying to get it to do) is create a document, set the field value, save it close it, then go to the next document. I realize this can all be done in lotusscript on the backend but for the sake of an exercise, how do I get it to save/close before continuing the loop in formula?

Subject: Why do this in @Formula?

@Formula often has a speed advantage, but when you’re doing 2000 dblookups it doesn’t. Change your code to Lotusscript. That way you can also easily debug it.

Subject: Come on guys!

…did you even read why I wanted to do this?

I quote: “…I realize this can all be done in lotusscript on the backend but for the sake of an exercise…”

Subject: well …

I would expect that your IF statement is not resulting to True because you are not actually saving the document so it’s resulting to false and doing nothing. Try just saving it and closing it without doing the IF portion and see if that works.

Subject: ditto

use lotusscript