Populating NAB with LotusScript

I have a LotusScript agent that runs when a user profile is saved on the web.  It runs fine.  There is a similar piece of LotusScript that does essentially the same thing, only it is stored in the QuerySave event and is used from the Client only.

What I want to do is take this same piece of code and make an agent out of it, so I can run it manually on selected documents.  However, there is some UI scripting in there...and frankly, I am so lost with LotusScript, I just don't know how to make this work.

Here is the code that works perfectly fine in the QuerySave event.  Mind you, it runs when a document is submitted.  I want to make it work from a view on selected documents (actually, when you get right down to it--it will be running on all the documents in this particular view).

I need this working ASAP.  We are moving our application from one server to another server, hopefully by the end of the year.  This is the only thing that's holding me up.  What the agent does, essentially, is write the person's name in the appropriate group(s) in the NAB.

Sub Querysave(Source As Notesuidocument, Continue As Variant)
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim groups As NotesView
     Dim doc As NotesDocument
     Dim workspace As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     Dim nab As New NotesDatabase( "", "" )
     Dim joinGroups As NotesItem
     Dim groupDoc As NotesDocument
     Dim groupMembers As NotesItem
     Dim servername As String
     '** Set Current Database **
     '** Set current Notes document to update field values
     Set db = session.CurrentDatabase
     Set uidoc = workspace.CurrentDocument
     Call uidoc.Refresh
     Set doc = uidoc.Document
     
     ' Handle New User Profile
     
     Set joinGroups = doc.GetFirstItem( "GroupsToJoin" )
     servername = db.Server
     Call nab.Open( servername, "names.nsf" )
     Set groups = nab.GetView("Groups")
     
     Forall x In joinGroups.Values
          Set groupDoc = groups.GetDocumentByKey(x)
          Set groupMembers = groupDoc.GetFirstItem("Members")
          If Not groupMembers.Contains(doc.CompleteName(0)) Then
               Call groupMembers.AppendToTextList(doc.CompleteName)
               Call groupDoc.Save(False, True)
          End If
         
     End Forall
     
End Sub

Thanks,

Panicking Carole
kroleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

melbor1Commented:
Sub Initialize
     Dim session As New NotesSession
     Dim collection as NotesDocumentCollection    
     Dim db As NotesDatabase
     Dim groups As NotesView
     Dim doc As NotesDocument
           Dim nab As New NotesDatabase( "", "" )
     Dim joinGroups As NotesItem
     Dim groupDoc As NotesDocument
     Dim groupMembers As NotesItem
     Dim servername As String
     Dim i as integer 'counter
     '** Set Current Database **
     '** Set current Notes document to update field values
     '**set the collection to all selected docs in the view
     Set collection = db.UnprocessedDocuments
     Set db = session.CurrentDatabase

    '** go through each doc in the collection and perform the operation
    For i = 1 to collection.Count  
    Set doc = collection.GetNthDocument( i )
     ' Handle New User Profile
     
     Set joinGroups = doc.GetFirstItem( "GroupsToJoin" )
     servername = db.Server
     Call nab.Open( servername, "names.nsf" )
     Set groups = nab.GetView("Groups")
     
     Forall x In joinGroups.Values
          Set groupDoc = groups.GetDocumentByKey(x)
          Set groupMembers = groupDoc.GetFirstItem("Members")
          If Not groupMembers.Contains(doc.CompleteName(0)) Then
               Call groupMembers.AppendToTextList(doc.CompleteName)
               Call groupDoc.Save(False, True)
          End If
           
     End Forall
    Next  
End
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
melbor1Commented:
In your agent:

When should the agent run?
   Manually from the Actions Menu
Which documents should it act on?
   Selected documents
0
kroleAuthor Commented:
It should run manually on selected documents in the view.  In this case, I will be selecting ALL of the documents in this particular view.

I copied/pasted your code and tried to run it.  It gives an 'object variable not set' on the line that reads "Set collection = db.UnprocessedDocuments"

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

kroleAuthor Commented:
It should run manually on selected documents in the view.  In this case, I will be selecting ALL of the documents in this particular view.

I copied/pasted your code and tried to run it.  It gives an 'object variable not set' on the line that reads "Set collection = db.UnprocessedDocuments"

0
melbor1Commented:
I'm sorry,
switch the order of the lines:
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments

0
kroleAuthor Commented:
We're getting closer!  :)

Ok, here's what happens.  This time it gives me the message:  "This database object is already open as DLEDT/SERVER/DEV!!names.nsf"  This only happens when I select multiple documents.  When I try running it by not selecting any documents at all, it only runs on the first document in the view.

Thanks SO MUCH for your help!!
0
melbor1Commented:
Try moving this information out of first for loop:

servername = db.Server
Call nab.Open( servername, "names.nsf" )
Set groups = nab.GetView("Groups")

It's trying to reopen the NAB when it's already open.
0
kroleAuthor Commented:
It works!!!  You have just made my entire year!!!  Thank you SOOO MUCHHH!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.