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.
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.
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
Change the Language Selector from Simple action(s) to LotusScript.
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) Wend Print "Complete" End Sub
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
Reference Library Applications
Design Enhancements Using LotusScript
Design Enhancements Using Formula Language
Miscellaneous Enhancements and Tips for Domino Databases
Application Deployment and Maintenance
Appendix A. Online Project Files and Sample Applications
Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
Authors: Mark Elliott
Similar book on Amazon
XPages Portable Command Guide: A Compact Resource to XPages Application Development and the XSP Language
Secure Programming Cookbook for C and C++: Recipes for Cryptography, Authentication, Input Validation & More
The New Solution Selling: The Revolutionary Sales Process That Is Changing the Way People Sell [NEW SOLUTION SELLING 2/E]