Modifying Data Using a LotusScript Agent

Table of contents:

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




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

Security

Application Deployment and Maintenance

Troubleshooting

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