[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1634
  • Last Modified:

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
0
krole
Asked:
krole
  • 4
  • 4
1 Solution
 
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
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now