Problem solve Get help with specific problems with your technologies, process and projects.

Can documents create and manipulate multiple other documents?

I have a document that holds a single idea for multiple vehicle lines with unique multiple savings for each vehicle line. When the idea becomes 80% feasible (which is set by a field), I need the document to create multiple documents for each vehicle line and their unique savings while copying the rest of the fields into each document. Is this possible? If so, please advise.
Sure. In your original document, let's say you have two multi-value fields -- VehicleLine and LineSavings. The fields must contain the same number of values, so that the Nth value in one field corresponds to the Nth value in the other. You could write LotusScript code as follows (this assumes you've already used agent selection criteria or some other means to filter out all but the 80% feasible documents).
Sub ExplodeLines(docOriginal As 
        Dim docNew As NotesDocument 
        Dim varLinesArray As Variant 
        Dim varSavingArray As Variant 
        Dim intIndex As Integer 
        Dim db As NotesDatabase 
        varLinesArray = docOriginal.
        varSavingArray = docOriginal.
        If Ubound(varLinesArray) <> 
Ubound(varSavingArray) Then 
                Error 23078, "Invalid Idea Document" '
 i just made up that error number 
        End If 
        If Ubound(varLinesArray) = 0 Then 
                ' the document only mentions one
 line -- we don't have to do anything. 
                Exit Sub 
        End If 
        Set db = docOriginal.ParentDatabase 
        ' for all entries except the first in 
the multivalues, create a new document. 
        For intIndex = 1 To Ubound(varLinesArray) 
                Set docNew = db.CreateDocument( ) 
                Call docOriginal.CopyAllItems
(docNew, False) 
                Call docNew.ReplaceItemValue
("VehicleLine", varLinesArray(intIndex)) 
                Call docNew.ReplaceItemValue
("LineSavings", varSavingArray(intIndex)) 
                docNew.Save True, False, True 
        ' remove all but the first item in each 
list from the original document. 
        ' Now there's a separate document 
for each of the original list values. 
        Call docOriginal.ReplaceItemValue
("VehicleLine", varLinesArray(0)) 
        Call docOriginal.ReplaceItemValue
("LineSavings", varSavingArray(0)) 
        docOriginal.Save True, False, True 
' note: don't force save unless the code is 
running when you're sure nobody is editing the document! 
End Sub

Dig Deeper on LotusScript

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...