Monday, 9 April 2018

The Power of LotusScript Part IV - CurrentView.DeselectAll

Last Friday I came again across the problem that documents remained selected after a View Action was executed. In the view were repeatedly a number of documents selected to be processed. The problem concerned a LotusScript agent using the UnprocessedDocuments method. As before I initially tried, by using the UpdateProcessedDoc method, to provide the documents of a 'processed stamp' so that these documents would not be processed  by the same Agent again. Unfortunately, this had no effect and the documents remained selected when the View Action was executed again for the next documents. The strange thing was that the documents were no longer visible in the view after they were processed but nevertheless remained selected. Eventually I found the solution on my own blog. In order not to forget this in the future I added the solution to my blog series as a reminder for myself.

The Power of LotusScript
Part I - Create New Document From UIdocument Using LotusScript
Part II - LotusScript Agent Send Email to Multiple Receipients (Per Recipient) Including a Doc Link Based on a Search Formula
Part III - Quick Tip - OpenDocumentInUI - OpenDocumentOtherDBInUI
Part IV - CurrentView.DeselectAll

On the IBM Support site I came across the following Technote (FAQ), View actions leave documents selected after execution in which my problem was described

After executing a View action in Notes/Domino, documents that were selected prior to running the View action are still selected, even when one or more documents no longer appear in the view. This can have adverse effects because a user may not realize that documents in other views may be selected when they execute the same action, a second action, or an agent that acts on currently selected documents.

Example of an adverse effect
An action uses LotusScript to act on selected documents using the UnprocessedDocuments property of the NotesDatabase class. If the action modifies documents so that they no longer appear in the view, a user would not realize that the documents were still selected after running the action. If the same View action is executed again (or another action that also uses the UnprocessedDocuments property), then documents in other views could be acted upon without the user realizing it.

The final solution (workaround) consists of the addition of CurrentView.DeselectAll in de LotusScript Agent.

Sub Click(Source As Button)
Dim s As New notessession
Dim db As notesdatabase
Dim col As notesdocumentcollection
Dim w As New notesuiworkspace

Set db=s.CurrentDatabase
Set col=db.UnprocessedDocuments
Set doc=col.GetFirstDocument
While Not (doc Is Nothing)
Set doc=col.GetNextDocument(doc)
Call w.CurrentView.DeselectAll
End Sub

I hope that the above solution will help someone with the same problem that I encountered now for the second time. In my next blog posts more LotusScript Functions and Agents that I have implemented during the past period in various Notes applications.

1 comment:

  1. Great tip Johnny. It seems there are so many developers who don't this one as I've discovered over the years supporting others code. It's a simple thing to implement, but you have to know it exists in the first place. Thanks for sharing.

    P.S enjoying the "The Power of LotusScript" series.