Tip

Mass Update Agent

Al Wiesner & Paul Asadoorian
This agent can be run in any database without any modifications. Just copy in
the dialogbox form and the agent and you are ready to go. This agent will act
on selected documents. When run the agent will get a count of how many forms
are in the database and dimension an array to that count. Then it will cycle
through the selected documents and store the different form types in the array
(no duplicates). Then it will save those form types in an environment
variable. Then the user will be prompted with a dialog box that gives a
combobox list of the different types of forms for selected documents. The user
then selects a form. Then the user is prompted the same dialogbox except this
time the values are that of all fields that are on that form type. The user
then selects a field. Then the user is prompted for a new value. Finally the
agent will run through the document collection and update every documents field
that uses that form with the new user supplied variable.
This agent was created jointly by Al Wiesner and Paul Asadoorian.
Create a dialog box with the following a field called "ChoiceBox" that is a
combobox and type of editable. The default value should be the following
formula:

Choice := @TextToNumber(@Environment("DispWhat"));
@If(Choice = 1; @Trim(@Explode(@Environment("FormArray"); ":"));
@Trim(@Explode(@Environment("FieldArray"); ":")))

Agent Script:

(Declarations)
Dim curDB As NotesDatabase
Dim FormArray() As String
Dim FieldArray() As Variant

(initialize)
Sub Initialize
Dim s As New NotesSession
Dim curColl As NotesDocumentCollection
Dim FormName As String
Dim FieldName As String
Dim FormCnt As Integer
Dim DispWhat As Integer

'get a count of the number of forms in the database to set the array
FormCnt = GetFormCount


'get selected documents
Set curDb = s.CurrentDatabase
Set curColl = CurDB.UnprocessedDocuments

GetAnotherFormName:

'get a non-duplicate array of form types for selected documents
'returns a 1to pass to PromptDialog so it will show the form dialog box
DispWhat = GetForms(curColl, FormCnt)

' prompt with list of forms to edit by
FormName = PromptDialog(DispWhat)

If FormName = "Exit" Then
Exit Sub
End If
'get an array of all fields that are on the selected form type for selected
documents
'returns a 2 to pass to PromptDialog so it will show the fields dialog box

DispWhat = GetFields(FormName)

'prompt with a list of fields to edit
FieldName = PromptDialog(DispWhat)

If FormName = "Exit" Then
Exit Sub
End If
'edit the doc by form and mass change all documents by FormName in the document
'collection
Call EditDocs(FormName, FieldName, curColl)

Goto GetAnotherFormName

End Sub


GETFORMCOUNT FUNCTION
Function GetFormCount As Integer
Dim session As New NotesSession
Set curDB = session.CurrentDatabase
Dim cnter As Integer

Forall form In curDB.Forms
cnter = cnter + 1
End Forall

GetFormCount = cnter
End Function


GETFORMS FUNCTION
Function GetForms(curColl As NotesDocumentCollection, FormCnt As Integer) As
Integer
Dim curDoc As NotesDocument
Dim S As New NotesSession
Dim FirstTime
FirstTime = True
Dim ArrayPos As Integer
Dim cnt As Integer
Dim i As Integer
Dim value As Variant
Dim value2 As Variant
Dim compare As Integer
Dim value1 As String
Dim EnvirString As String
Dim J As Integer
Redim FormArray(FormCnt) As String

Set curDoc = curColl.GetFirstDocument

While Not(curDoc Is Nothing)
If FirstTime Then
value = curDoc.GetItemValue("form")
value1 = value(0)
FormArray(0) = value1
FirstTime = False
ArrayPos = ArrayPos + 1
Goto AfterFirst
End If

For i = 0 To FormCnt
value = curDoc.GetItemValue("form")
value1 = value(0)
If value1 = FormArray(i) Then
Goto AfterFirst
End If

If i = FormCnt Then

If value1 = FormArray(i) Then
Goto AfterFirst
End If
value = curDoc.GetItemValue("form")
value1 = value(0)
FormArray(ArrayPos) = value1
cnt = cnt + 1
ArrayPos = ArrayPos + 1
End If
Next i

AfterFirst:
Set curDoc = curColl.GetNextDocument(curDoc)
Wend
FirstTime = True

For J = 0 To Cnt
If FirstTime Then
EnvirString = FormArray(J)
FirstTime = False
Goto AnotherJ
End If
'create a colon delimited string to save in an environment variable to be
called by
'the dialog box
EnvirString = EnvirString & ":" & FormArray(J)
AnotherJ:
Next J

Call S.SetEnvironmentVar("FormArray", EnvirString, False)
GetForms = 1
End Function


<WHATLEIG

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.