Link to home
Start Free TrialLog in
Avatar of krole
krole

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of melbor1
melbor1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of melbor1
melbor1

In your agent:

When should the agent run?
   Manually from the Actions Menu
Which documents should it act on?
   Selected documents
Avatar of krole

ASKER

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"

Avatar of krole

ASKER

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"

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

Avatar of krole

ASKER

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!!
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.
Avatar of krole

ASKER

It works!!!  You have just made my entire year!!!  Thank you SOOO MUCHHH!!!