Wie oft ist es schon vorgekommen, daß man in einer Datenbank feldwerte ändern mußte.
Es mag ja noch angehen, daß man einzelne Dokument manuell bearbeitet; aber wie sieht es bei > 100 ode > 1000 aus.
Möglicherwesie sind auch noch Änderungen an mehr als einem Feld pro Dokument vonnöten.
Der folgende Code in einen Agenten gepackt und schon kann es losgehen.
Der Agent muß nicht an jede Datenbank angepasst werden.
Copy & Play heißt das Motto
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 = ""
Else
' 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
Do
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
Else
itemstring$ = ""
End If
Set tempitem = doc.GetFirstItem(item.name)
If tempitem Is Nothing Then
tempstring$ = ""
Elseif Datatype(tempitem.text) = 8 Then
tempstring$ = tempitem.text
Else
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 doc.save(True, True, True)
Set doc = collection.GetNextDocument(doc)
Wend
End Sub