Tuesday, March 2, 2010

Formula-Agent and @Prompt

I had to write a small maintenance agent to reset NotesItems, and, to not accidentally trigger it, I used the @Prompt function to ask the typical "Are you really sure?" question - not a good idea ;-)

The result was, that I had to keep clicking message boxes until the agent was finally done - fortunately there where only 42 documents in the databases, which made me click 42 times.

Here is why; I used the following agent, with the options "Action menu selection" and "All selected documents":

@If(!@Prompt([YesNo]; "Reset fields"; "Are you sure?"); @Return(""); "");
@SetField("Body"; "");
@SetField("nbMemos"; 0);
[...]
SELECT @All

If you do this, the result is, that Notes triggers the agent for each document (actually "of course" ;-)) and asks for each document separately; could be kind of useful if this is what you want it to do, but you should never try this on a database storing some thousand documents :-)

A better way to accomplish the task would be to write the agent in LotusScript, even though it is a lot longer:

'RESET MAIL FIELDS:

Option Public
Option Declare
%INCLUDE "lsconst.lss"
Sub Initialize

On Error Goto errorhandler

Dim s As New NotesSession

Dim db As NotesDatabase
Set db = s.CurrentDatabase

Dim doccoll As NotesDocumentCollection
Set doccoll = db.UnprocessedDocuments

If doccoll Is Nothing Then
Exit Sub
End If

If Msgbox("Are you sure?", MB_YESNO, "Reset fields") <> IDYES Then
Exit Sub
End If

Call doccoll.StampAll("Body", "")
Call doccoll.StampAll("nbMemos", 0)
[...]

e:
Exit Sub
errorhandler:
Msgbox "Error " & Error & " in line " & Erl
Resume e
End Sub

1 Comments:

Anonymous David Leedy said...

Marcus,

Great Post. I use the "Are you sure?" technique a lot as well.

One thing I like to add to the message - is the count of the collection.

so something like:

"Are you sure you want to update " & collect.count & " documents?"

This gives the user additional visibility of how MANY documents are selected. In case they accidentally have more selected then they realize.

March 2, 2010 1:31 PM  

Post a Comment

Thank you for your comment. It will be published shortly. Keep having a great day!

<< Home