Hey Everyone, Hopefully someone could lend a helping hand, it would be much appreciated forehand.
Previewed below is a code I have set as an approve button as an agent. THere are predifined Approvers as FirstApprover and SecondApprover. Once both approvers approve the doc, then the status should be changed to “Approve”
An email is suppose to be sent to the second approver after the first approver approves but it doesnt do that. I believe there is an error in the code, but I just cant find it and dont know Lotusscript well enough to debug this.
Any assisstance is Greatly appreciated forehand.
Thank you!
Sub Initialize
On Error Goto errHandler
Dim ws As New NotesUIWorkspace
Dim s As New NotesSession
Dim doc As NotesDocument
Dim user(0) As String, firstapprovers As Variant, secondapprovers As Variant, comparr As Variant, compfld As String
Dim ismem1 As Variant, ismem2 As Variant
Dim apptype As Integer
Dim histentry As String, histitem As NotesItem, histlist As Variant
Dim subject As String, bodytext As String, linkmsg As String, ordernum As String, recipient As String
Set doc = ws.CurrentDocument.Document
REM get the approver lists, user name
user(0) = s.UserName
firstapprovers = doc.GetItemValue("FirstApprovalsPending")
secondapprovers = doc.GetItemValue _
("SecondApprovalsPending")
REM add the user's name to the appropriate complete item
If apptype = 1 Then
compfld = "FirstApprovalsComplete"
Else
compfld = "SecondApprovalsComplete"
End If
comparr = doc.GetItemValue(compfld)
Call doc.ReplaceItemValue(compfld, Arrayunique(Fulltrim(Arrayappend(comparr, user))))
REM add the comments, user name, and date/time to the history
histentry = s.CommonUserName & "[APPROVED] (" & Now & ")" & Chr(10) & doc.GetItemValue("ApproverComments")(0) &_
Chr(10) & "________________________" & Chr(10)
Set histitem = doc.getFirstItem("ApprovalHistory")
histlist = doc.ApprovalHistory
Call doc.ReplaceItemValue("ApprovalHistory", histentry)
Call histitem.AppendToTextList(histlist)
ordernum = doc.GetItemValue("OrderNumber")(0)
REM if the first approvers are done then send to first second approver
Call doc.ComputeWithForm(False, False)
firstapprovers = doc.GetItemValue("FirstApprovalsPending")
If firstapprovers(0) = "" And Ubound(firstapprovers) = 0 Then
secondapprovers = doc.GetItemValue("SecondApprovalsPending")
If secondapprovers(0) = "" And Ubound(secondapprovers) = 0 Then
REM if there are no more approvers, mark the document as approved, route to creator of doc
subject = "Modification Approved! - Coupon Modification Database (" & ordernum & ")"
bodytext = "Your request has passed through the approval process with flying colors!"
recipient = doc.GetItemValue("CreatedBy")(0)
linkmsg = "Link to Request #" & ordernum
doc.ApprovalStatus = "Approved"
Else
REM if it is a second approver, send the msg to the next approver
subject = "Second Level Approval Due (" & ordernum & ")"
bodytext = "This request is pending your approval. Please follow the doclink to the request and approve or reject it."
linkmsg = "Link to Order #" & ordernum
recipient = secondapprovers(0)
End If
REM SendMail(Subject As String, BodyMsg As String, recips As Variant, linkdoc As Variant, linkmsg As String)
Call sendMail(subject, bodytext, recipient, doc, linkmsg)
End If