Modifying Data Using a LotusScript Agent
One way to modify data is through the use of agents. This section illustrates how to use LotusScript to change data stored in the database. This option provides the capability to perform much more complex logic or transactions against the data. For example, you may only want to act on documents in a particular view within a certain data range or skip documents that already have a specified value. See Chapter 16, "Sample Agents," for a simple action agent that can be used to modify data.
How It Works
When the agent is triggered, the LotusScript code loops through all documents in a specific view. Field values are checked for each document. When a field (or document) matches the specified value, field values for the document are updated or replaced. Then the looping continues with the next document in the view.
Implementation
To implement this technique, complete the following steps.
Step 1. | Create the agent. Select the Create > Design > Agent menu options to create the agent. When the properties dialog displays, give the agent a name. Next, set the runtime trigger parameters to On event, Action menu selection, and None. Close the properties dialog after these values have been defined.
|
Step 2. | Add the code. In the Programmers pane, change the Language Selector from Simple action(s) to LotusScript and insert the following LotusScript code in the Initialize section. Be sure to replace VIEW and FIELD with valid design element names. Replace VALUE1 with a text string to search and VALUE2 with a replacement text string.
|
Note
This example is designed to work with a non-categorized view. Errors may occur if the field being changed is also used as the categorized column formula.
--------------------------------------------------- Define the objects --------------------------------------------------- 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") Call view.Refresh view.AutoUpdate = False --------------------------------------------------- Check all documents in the view --------------------------------------------------- Print "Starting data updates" 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 "Data updates complete" End Sub
Категории |