lotus-noteslotusscriptlotus-formula

Lotus Notes - Script or formula to create multiple new documents within a database


I have the following situation:
currently an end user needs to create several documents using a step by step process, but with some new features that was created, the user will need to create more required documents.
I am afraid they will forget to create an important one that will mess the process at the end.
Based on this I was thinking to create a script, since the Compose @Command (Formula Language) allows me to create only one form.

Note that these documents will have computed fields, so no need to fill any data on these new forms.

Here is what I got so far, it is working but I think someone could give a better idea. Thanks.

    Dim session As New notessession
    Dim db As notesdatabase
    Dim newdoc As notesdocument
    Dim i%
    
    Set db=session.currentdatabase
    
    For i%=1 To 1 'or however many slots you want
        
        Set newdoc=db.createdocument
        newdoc.form= "Form1"
        Call newdoc.save(True,True)
        
        Set newdoc=db.createdocument
        newdoc.form="Form2"  
        Call newdoc.save(True,True)     
        
        Set newdoc=db.createdocument
        newdoc.form="Form3"
        Call newdoc.save(True,True)
                
    Next i%
End Sub

Solution

  • If you want to make the documents compute as if they were opened in frontend, then you need to tell the code to do that: simple saving a document does NOT do frontend calculations. You need to add a ComputeWithForm before every save to do exactly that: compute the document with the assigned form. That will look like this:

        Set newdoc=db.createdocument
        newdoc.form= "Form1"
        Call newdoc.ComputeWithForm( True, True )
        Call newdoc.save(True,True)
    

    Take care: if there is any error in the formulas of your form because you forgot to fill some essential field, then the compute will not complete and only fields above the one that had the error will be calculated. In addition this funcion may throw an Error if something goes wrong that you have to catch in your code (depends of parameters, check documentation)