developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum

developerWorks




RunOnServer apparently not running
Mark XY Brown 11/01/2012 01:14 PM
Domino Designer 6.0.3 Windows XP


Got another frustration here.

The Powers That Be like having a Notes database to handle the invitations to the Christmas party each year. Each year, the databases need more and more features. My problem this year is to create an action against an Invitee document that will allow the organisers to manually send an invitation to a latecomer.

The database has a number of forms. The ones impacted here are:
Invitee (Name and address of invitee, as well as their internal/external flag, and Invited, Responded and Attending flags)
OGM (Message title, invitation flag, whether this message is destined for internal or external invitees, message fields)

As it takes fields from two documents to compose a message, I set up an action on the Invitee form and an agent.

The action prompts the organiser for a message (workspace pick list, source view categorised on the invitee's internal/external status), and then dumps the message's UNID and the invitee's UNID into a temporary document. It passes the note ID of the temporary document to the agent.

The agent calls back the temporary document and then interrogates it for the UNIDs of the other two documents. Then it analyses the values in them and composes an invitation accordingly. It sends and then purges the invitation, and deletes the temporary document.

The action, meanwhile, has been polling the database for the temporary document. As soon as it's not found, it alerts the organiser that the invitation has been sent.

Well, that was the plan. If I step through the code, I can generate a temporary document. I can then manually call back that document in the agent, and the code all runs as I expect. If I try letting it run normally, the action generates an endless loop.

Action script:
Sub Click(Source As Button)
'2012-Nov-01
'Pass parameters to the (ManualSend) agent to invite this person

Dim ws As New NotesUIWorkspace
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim agnSend As NotesAgent
Dim namServer As NotesName
Dim docThis As NotesDocument
Dim docParam As NotesDocument

Dim strServer As String
Dim strFile As String
Dim strInt As String
Dim varOGMID As Variant
Dim strOGMID As String
Dim strInvID As String
Dim strParam As String

Set db = sess.CurrentDatabase
Set docThis = ws.CurrentDocument.Document
Set agnSend = db.GetAgent("(ManualSend)")
Set docParam = New NotesDocument(db)

Set namServer = New NotesName(db.Server)
strServer = namServer.Common

strFile = db.FilePath
strFile = Left(strFile, Instr(1, strFile, ".")-1)

strInt = docThis.GetItemValue("IsInternal")(0)

varOGMID = ws.PickListStrings(PICKLIST_CUSTOM, False, strServer, strFile , _
"Messages", "Manually send invitation", _
"Select an OGM to use for " & docThis.GetItemValue("FullName" & strInt)(0), _
4, strInt)

If Isempty(varOGMID) Then Exit Sub

strOGMID = varOGMID(0)
strOGMID = Left(strOGMID, Instr(1, strOGMID, "~")-1)

strInvID = docThis.GetItemValue("DocRefID")(0)

docParam.InvID = strInvID
docParam.OGMID = strOGMID
Call docParam.Save(True, False)
strParam = docParam.UniversalID

Set docThis = Nothing 'Precaution against the agent not being able to modify this doc

Call agnSend.RunOnServer(strParam)

Set docParam = Nothing
Set docParam = db.GetDocumentByUNID(strParam)

Do Until docParam Is Nothing

Set docParam = Nothing
Set docParam = db.GetDocumentByUNID(strParam)

Loop

Messagebox "Invitation sent!", 64, "Manually send invitation"

End Sub

Agent script:
Sub Initialize
'2012-Nov-01
'Send out an invitation to the person named in the passed document

Dim sess As New NotesSession
Dim db As NotesDatabase
Dim agnThis As NotesAgent
Dim docParam As NotesDocument
Dim docInv As NotesDocument
Dim docOGM As NotesDocument
Dim docMemo As NotesDocument

Dim strParam As String
Dim strInvID As String
Dim strOGMID As String
Dim strName As String
Dim strMessage As String

Set db = sess.CurrentDatabase
Set agnThis = sess.CurrentAgent
strParam = agnThis.ParameterDocID
Set docParam = db.GetDocumentByUNID(strParam)

Set docInv = db.GetDocumentByUNID(docParam.GetItemValue("InvID")(0))
Set docOGM = db.GetDocumentByUNID(docParam.GetItemValue("OGMID")(0))

strOGMID = docOGM.GetItemValue("OGMID")(0)
strInvID = docInv.GetItemValue("InvID")(0)

If docInv.GetItemValue("IsInternal")(0) = "E" Then

'External invitee
Set docMemo = New NotesDocument(db)

strName = docInv.GetItemValue("FullNameE")(0)
strName = Left(strName, Instr(1, strName, " ")-1)

strMessage = docOGM.GetItemValue("FormOfAddress")(0)
strMessage = strMessage & strName & Chr(13) & Chr(13)
strMessage = strMessage & docOGM.GetItemValue("BodyText")(0)

With docMemo

.Form = "Memo"
.SendTo = docInv.GetItemValue("ExternalAddress")(0)
.Subject = docOGM.GetItemValue("Subject")(0)
.Body = strMessage

End With

Else

'Internal invitee
Set docMemo = docOGM.CopyToDatabase(db)
docMemo.SendTo = docInv.GetItemValue("NotesName")(0)
docMemo.Form = "Memo"

End If

Call docMemo.ComputeWithForm(False, False)
Call docMemo.Send(False)
Call docMemo.RemovePermanently(True)
Set docMemo = Nothing

docInv.Invited = "1"
Call docInv.Save(True, False)

Call docParam.RemovePermanently(True)

End Sub

Any ideas?
Thanks for reading this far!

Go back