Jaziar
asked on
Email Agent Revisited
I fully understand this agent is coded very poorly. The problem I have is I don't have the time to go back and rewrite the code. I really need to put a PartNumber in the subject field. There is a form with a Approve action button on it. The action button is pressed it runs this agent. I need to get the PartNumber off the form and place it in the subject line in the email. We have looked at this before, but it did not work correctly. Also when the agent sends out the email it is from the last person to save the agent, It should be from the database.
This is a large agent so I going to place all the code in here.
Declarations **************
Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocument
Dim mailDoc As NotesDocument
Dim approverFieldList(6) As String
Dim approverList(6) As String
Initialize**************** ********** ******
Sub Initialize
Call InitializeGlobals()
If dc.SaveOnlyFlag(0) <> "1" Then
If IsRejected(dc) Then
Call SendRejectionNoticeToInspe ctor
Else
recipient = WhoAmIMailingTo()
If recipient = dc.ApprovalInspectedBy(0) Then
SendLinkToInspector(recipi ent)
Elseif recipient <> "" Then
SendLinkToApprover(recipie nt)
End If
End If
End If
End Sub
InitializeGlobals********* ********** ********** *********
Function InitializeGlobals
Set session = New NotesSession
Set db = session.CurrentDatabase
Set dc = session.DocumentContext
Set mailDoc = db.CreateDocument()
approverFieldList(0) = "AssignedQE"
approverFieldList(1) = "AssignedPME"
approverFieldList(2) = "AssignedPEDE"
approverFieldList(3) = "AssignedQEMan"
approverFieldList(4) = "AssignedPMEMan"
approverFieldList(5) = "AssignedPEDEMan"
For i = 0 To 5
approverList(i) = ""
Next
End Function
WhoAmIMailingTo*********** ********** ********** *
Function WhoAmIMailingTo As String
Dim item As NotesItem
WhoAmIMailingTo = ""
'If signed by last approver then mail goes back to the inspector
If dc.HasItem("ApprovalPEDESi gnatureMan ") Then
Set item = dc.GetFirstItem("ApprovalP EDESignatu reMan")
If item.text <> "" Then
WhoAmIMailingTo = dc.ApprovalInspectedBy(0)
Else
For i = 0 To 5
approverList(i) = dc.GetItemValue(approverFi eldList(i) )(0)
Next
For i = 5 To 0 Step -1 'send mail to next approver
If approverList(i) <> "" Then
WhoAmIMailingTo = approverList(i)
Exit For
End If
Next
End If
Else
For i = 0 To 5
approverList(i) = dc.GetItemValue(approverFi eldList(i) )(0)
Next
For i = 5 To 0 Step -1 'send mail to next approver
If approverList(i) <> "" Then
WhoAmIMailingTo = approverList(i)
Exit For
End If
Next
End If
End Function
SendLinkToApprover******** ********** ********** **
Function SendLinkToApprover(recipie nt As String)
Dim rtitem As NotesRichTextItem
mailDoc.SendTo = recipient
mailDoc.Subject = "A Metrology Specification Requires Your Approval"
Set rtitem = mailDoc.CreateRichTextItem ("Body")
Call rtitem.AppendText("Click on the link below to access the approval document")
Call rtitem.AddNewLine(2)
linkString = "https://knetus4.place.lexmark.com" & dc.HTTPDbLoc(0) & "/0/" & dc.DocID(0) & "?EditDocument"
Call rtitem.AppendText(linkstri ng)
mailDoc.Send(False)
End Function
There are a couple more, but I think if we can get SendLinkToApprover to work the others should be simple to fix. In the mailDoc.Subject = "A Metrology Specification" & PartNum & " Requires Your Approval" I need to get the value of PartNum off the form. I also need for the emails be from the database and not the last person who saved the agent.
This is a large agent so I going to place all the code in here.
Declarations **************
Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocument
Dim mailDoc As NotesDocument
Dim approverFieldList(6) As String
Dim approverList(6) As String
Initialize****************
Sub Initialize
Call InitializeGlobals()
If dc.SaveOnlyFlag(0) <> "1" Then
If IsRejected(dc) Then
Call SendRejectionNoticeToInspe
Else
recipient = WhoAmIMailingTo()
If recipient = dc.ApprovalInspectedBy(0) Then
SendLinkToInspector(recipi
Elseif recipient <> "" Then
SendLinkToApprover(recipie
End If
End If
End If
End Sub
InitializeGlobals*********
Function InitializeGlobals
Set session = New NotesSession
Set db = session.CurrentDatabase
Set dc = session.DocumentContext
Set mailDoc = db.CreateDocument()
approverFieldList(0) = "AssignedQE"
approverFieldList(1) = "AssignedPME"
approverFieldList(2) = "AssignedPEDE"
approverFieldList(3) = "AssignedQEMan"
approverFieldList(4) = "AssignedPMEMan"
approverFieldList(5) = "AssignedPEDEMan"
For i = 0 To 5
approverList(i) = ""
Next
End Function
WhoAmIMailingTo***********
Function WhoAmIMailingTo As String
Dim item As NotesItem
WhoAmIMailingTo = ""
'If signed by last approver then mail goes back to the inspector
If dc.HasItem("ApprovalPEDESi
Set item = dc.GetFirstItem("ApprovalP
If item.text <> "" Then
WhoAmIMailingTo = dc.ApprovalInspectedBy(0)
Else
For i = 0 To 5
approverList(i) = dc.GetItemValue(approverFi
Next
For i = 5 To 0 Step -1 'send mail to next approver
If approverList(i) <> "" Then
WhoAmIMailingTo = approverList(i)
Exit For
End If
Next
End If
Else
For i = 0 To 5
approverList(i) = dc.GetItemValue(approverFi
Next
For i = 5 To 0 Step -1 'send mail to next approver
If approverList(i) <> "" Then
WhoAmIMailingTo = approverList(i)
Exit For
End If
Next
End If
End Function
SendLinkToApprover********
Function SendLinkToApprover(recipie
Dim rtitem As NotesRichTextItem
mailDoc.SendTo = recipient
mailDoc.Subject = "A Metrology Specification Requires Your Approval"
Set rtitem = mailDoc.CreateRichTextItem
Call rtitem.AppendText("Click on the link below to access the approval document")
Call rtitem.AddNewLine(2)
linkString = "https://knetus4.place.lexmark.com" & dc.HTTPDbLoc(0) & "/0/" & dc.DocID(0) & "?EditDocument"
Call rtitem.AppendText(linkstri
mailDoc.Send(False)
End Function
There are a couple more, but I think if we can get SendLinkToApprover to work the others should be simple to fix. In the mailDoc.Subject = "A Metrology Specification" & PartNum & " Requires Your Approval" I need to get the value of PartNum off the form. I also need for the emails be from the database and not the last person who saved the agent.
I don't understand. We solved this issue, didn't we??
mailDoc.Subject = "A Metrology Specification" & doc.PartNum(0) & " Requires Your Approval"
Emails will never be from the database, unless you create an additional User-ID, give it sifficent rights in the database and on the server, and sign the agent with that ID.
mailDoc.Subject = "A Metrology Specification" & doc.PartNum(0) & " Requires Your Approval"
Emails will never be from the database, unless you create an additional User-ID, give it sifficent rights in the database and on the server, and sign the agent with that ID.
ASKER
sjef bosman I thought we did as well, but it never worked.
I placed mailDoc.Subject = "A Metrology Specification" & doc.PartNum(0) & " Requires Your Approval"
in the agent and here we work off templates because we don't have access to the act. database. It replicated the next day and the agent failed.
I placed mailDoc.Subject = "A Metrology Specification" & doc.PartNum(0) & " Requires Your Approval"
in the agent and here we work off templates because we don't have access to the act. database. It replicated the next day and the agent failed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did the agent fail on that specific line?? What was the errormessage in the log database? There could have been other reasons. Did you include error-handling in your code?
In every function, have something like
On Error Goto onerror
...
exitsub:
Exit Sub
onerror:
Dim msg As String
msg= Error$ & " on line " & Erl
MessageBox msg
Error Err, msg
End Sub
You'll see all the lines where the error took place. Isn't it possible to run the agent manually? Using the Debugger?
In every function, have something like
On Error Goto onerror
...
exitsub:
Exit Sub
onerror:
Dim msg As String
msg= Error$ & " on line " & Erl
MessageBox msg
Error Err, msg
End Sub
You'll see all the lines where the error took place. Isn't it possible to run the agent manually? Using the Debugger?
ASKER
This worked bad code or not. The ending result is they are off my back.
Thanks
Thanks
Congrats! :)
or use another parameter in the function SendLinkToApprover, and pass the partnum
~Hemanth