Manage Learn to apply best practices and optimize your operations.

From One Form, Change Many Fields in Many Documents

This agent allows any authorised user to change any number of non-rich text fields in any number of documents. The agent can be added to any database without changing any other code.

Select the documents you want to change. One of the documents is displayed using its own form in a dialog box. Any changes made in the dialog box are then applied to every selected document.

Bet you can't do this from a Web client!

Sub Initialize
' Modify any non-rich text fields in all selected documents
' 1) Show one of the selected documents in a dialog box using its form
' (if no form or form not found in this database, prompt user for form name)
' 2) Copy all new and changed items to all selected documents, replacing existing items of the same name
' 3) (Optional) If the dialog box used the document's own form, save only if ComputeWithForm works
' Otherwise save but without computing with form.
Dim savecount%, tempstring$, itemstring$
Dim flag As Integer
Dim workspace As New Notesuiworkspace
Dim session As New Notessession
Dim thisdb As Notesdatabase
Dim collection As Notesdocumentcollection
Dim doc As Notesdocument
Dim dialogdoc As Notesdocument
Dim newdoc As Notesdocument
Dim tempitem As Notesitem
Dim dialogformname As String
Dim dialogform As NotesForm
Dim totalcount As Integer
Dim savedcount As Integer
Set thisdb = session.currentdatabase
Set collection = thisdb.unprocesseddocuments
totalcount = collection.count
Set dialogdoc = thisdb.createdocument
Set newdoc = thisdb.createdocument
Set doc = collection.GetFirstDocument
doc.ParentView.autoupdate = False
' Show copy of first selected document in dialog box
Call doc.CopyAllItems( dialogdoc )
' Get form name
Set tempitem = dialogdoc.GetFirstItem("Form")
If tempitem Is Nothing Then
dialogformname = ""
' If Notesitem.Text property is empty or null (or anything but text), use empty string
Select Case Datatype(tempitem.text)
Case 8: dialogformname = tempitem.text
Case Else: dialogformname = ""
End Select
End If
If dialogformname = "" Then
dialogformname = Inputbox( "Enter a form name for editing the document, or cancel to exit." , _
"Form not found for document" )
If dialogformname = "" Then
Print "You did not enter a form name, no updates were done."
Exit Sub
End If
End If
Set dialogform = thisdb.GetForm( dialogformname )
If dialogform Is Nothing Then dialogformname = ""
Loop Until dialogformname <> ""
flag = Workspace.DialogBox( dialogformname ,,,,,,,"IF YOU PRESS OK, ALL CHANGED FIELDS WILL BE PROPAGATED TO ALL SELECTED DOCUMENTS", dialogdoc)
If flag = False Then
Print "Dialog box was cancelled, no updates made."
Exit Sub
End If
' copy all new and changed items to newdoc
Forall item In dialogdoc.items
' If Notesitem.Text property is empty or null (or anything but text), use empty string
If Datatype(item.text) = 8 Then
itemstring$ = item.text
itemstring$ = ""
End If
Set tempitem = doc.GetFirstItem(
If tempitem Is Nothing Then
tempstring$ = ""
Elseif Datatype(tempitem.text) = 8 Then
tempstring$ = tempitem.text
tempstring$ = ""
End If
If itemstring$ <> tempstring$ Then
Call item.copyitemtodocument(newdoc, "")
End If
End Forall
While Not doc Is Nothing
Call newdoc.CopyAllItems( doc, True )
' If doc.form(0) = dialogformname Then Call doc.Computewithform(True, False)
savecount = savecount + 1
Print totalcount & " documents, " & savecount & " updated"
Call, True, True)
Set doc = collection.GetNextDocument(doc)
End Sub

Dig Deeper on Domino Resources - Part 5

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials'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 ...