LotusScript Agent to Modify All Documents Containing a Specific Field Value

Like simple actions, LotusScript can be used to manage and perform actions in a database. However, LotusScript offers greater flexibility to create more robust agents. This section illustrates how to modify all documents in a database where a field contains a specific value.


How It Works

For this example, LotusScript is used to iterate through database documents in a specific view and compare field values. When a match is found, the new value is assigned to the field, and the document is saved. The looping then continues with the next document in the list.

This example could be used to modify field values for select documents in a database view. Lets say, for example, that a team member has recently transferred to a new department. Using this sample, you could reassign all documents from one person to another person.


To implement this solution, complete the following steps.

Step 1.

Select the Create > Design > Agent menu options to create the agent. When the properties dialog displays, give the agent a name such as Reassign Documents and set the Runtime Target to None (see Figure 16.2). After these values are set, close the properties dialog.

Figure 16.2. Setting the runtime property for an agent

Step 2.

Change the Language Selector from Simple action(s) to LotusScript.

Step 3.

Insert the following code in the Programmers pane. Be sure to replace VIEW with the name of the view to iterate through, FIELD with the field name to check, VALUE1 with the comparison string, and VALUE2 with the replacement string. If the searchandreplace objects are numbers, remember to remove the quotes to indicate that the value is a number (and not a string).

Sub Initialize

 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim view As NotesView
 Set db = s.CurrentDatabase
 Set view=db.GetView("VIEW")

 Set doc = view.GetFirstDocument
 While Not (doc Is Nothing)

 If doc.FIELD(0) = "VALUE1" Then
 doc.FIELD = "VALUE2"
 End If
 Call doc.Save(True, False)
 Set doc=view.GetNextDocument(doc)

 Print "Complete"

End Sub

Step 4.

Save and close the agent to complete the configuration. To run the agent, open the database in the Lotus Notes client and select Reassign Documents from the Actions menu.


Performance for this agent will be affected by a variety of factorstotal documents in the database, total fields in the document, runtime location (server versus local), and so on. If performance becomes an issue, consider replacing If doc.FIELD(0) = "Value1" with the statement If doc.GetItemValue ("FIELD")(0) = "Value1". The GetItemValue method is more efficient and will improve overall agent performance for large databases.

An Introduction to the Lotus Domino Tool Suite

Getting Started with Designer

Navigating the Domino Designer Workspace

Domino Design Elements

An Introduction to Formula Language

An Introduction to LotusScript

Fundamentals of a Notes Application

Calendar Applications

Collaborative Applications

Reference Library Applications

Workflow Applications

Web Applications

Design Enhancements Using LotusScript

Design Enhancements Using Formula Language

View Enhancements

Sample Agents

Miscellaneous Enhancements and Tips for Domino Databases

Data Management


Application Deployment and Maintenance


Appendix A. Online Project Files and Sample Applications

Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?

Lotus Notes Developer's Toolbox(c) Tips for Rapid and Successful Deployment
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
ISBN: 0132214482
EAN: 2147483647
Year: N/A
Pages: 293
Authors: Mark Elliott

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net