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
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 groupDoc.Save(False, True)