1
votes

I have a list of document in view. I also have a button inside view where I can create new document with value from existed document. For this new document, I will use different form for new document created. In my view, document is divide by Status. I also has dialogBox too for me to set batchNo for new documents.

So, the process is like this:

  1. First, I will select document based on it status. So let's say I have 5 documents under "Spoilt" status, I can choose how many document I want. So I choose 2 documents only.
  2. After document selected, I will click button to create one new documents using lotusscript. After button clicked, DialogBox will show. I insert batchNo and click OK.
  3. Then, the code will check that status of documents and create new document by getting value from 3 documents and display into new document.
  4. For example, I need to get value from field "PSerialNo" and "PType" from 2 documents. As you can see below. Value from document1 and document2, I want to insert in new document. So if document1, PSerialNo into WSerialNo1 and PType into WType1. And if document2, PSerialNo into WSerialNo2 and PType into WType2 and so on.

Document 1
doc1
Document 2
doc2
New Document
newdoc

This is my code to create new document.

Set doc = dc.GetFirstDocument()

While Not (doc Is Nothing)
    If doc.PStatus(0) = "Active" Then
        Set newdoc = New NotesDocument(db)
        newdoc.Form = "WriteOff"            

        newdoc.WABatchNo = wDialogDoc.WBatchNo(0)
        newdoc.WType = doc.PType(0)
        newdoc.WSerialNo = doc.PSerialNo(0)

        newdoc.ComputeWithForm(False,False)
        newdoc.save(True,False)

    End If
    doc = dc.GetNextDocument(doc)
Wend

My problem now, if I create new document, and I want to get value from two documents, it not insert into one new document but it insert into two different new document. How can I fix it. Any advice or help I appreciate. Thanks!

1

1 Answers

1
votes

It's been more than 10 years since I wrote LotusScript, so I might be wrong.

Set doc = dc.GetFirstDocument()
Dim docCreated As Boolean 'flag a document was created
Dim i As Integer 'index for each document

docCreated = False
i = 0
While Not (doc Is Nothing)
    If doc.PStatus(0) = "Active" Then
        If Not docCreated Then 'only create a document for first doc
            Set newdoc = New NotesDocument(db)
            newdoc.Form = "WriteOff"
            docCreated = True
        End If
        i = i + 1

        newdoc.WABatchNo = wDialogDoc.WBatchNo(0)
        ' not sure about this part, but the idea is to set WType1 for first doc, WType2 for 2nd doc, and so on
        Call newdoc.ReplaceItemValue("WType" & i, doc.PType(0))
        Call newdoc.ReplaceItemValue("WSerialNo" & i, doc.PSerialNo(0))
    End If
    doc = dc.GetNextDocument(doc)
Wend

If docCreated Then
    Call newdoc.ComputeWithForm(False,False)
    Call newdoc.save(True,False)
End If