Subject: RE: Declaring a view
OK, a few things then.
You don’t need to get the view at all - you’re not actually doing anything with it, the view is simply showing the documents, so when the document updates the view will show the new values.
In the agent you’re changing the documentcontext document and sending it by email. You don’t want to do this as this will mess up your access requests view (which is why when the agent completes your view is now wrong).
This is completely untested but should be roughly what you need. Notice I don’t do anything, or resave doc, as this is done anyway, I’m creating new documents to email. I’ve also removed a load of code and variables that you weren’t using.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim names As NotesDatabase
Dim view As notesview
Set db = session.CurrentDatabase
Dim doc As NotesDocument
Dim emailDoc As NotesDocument
Dim email As String
Dim shortName As String
Dim Uname As String
Dim User As String
Dim FirstApprover As String
Dim FirstApproverEmail As String
Dim SecondApprover As String
Dim SecondApproverEmail As String
Dim Team As String
Dim SaveRef As String
'**** the current document, used to retrieve values for the emails only **********
Set doc = session.DocumentContext
‘******* create a new document to send by email *******’
set emaildoc = db.createdocument
user = doc.user(0)
email = doc.EmailAddressAuto(0)
FirstApprover = doc.FirstApprover(0)
FirstApproverEmail = doc.FirstApproverEmail(0)
SecondApprover = doc.SecondApprover(0)
SecondApproverEmail = doc.SecondApproverEmail(0)
Team = “Viraj.Patel@europe.co.uk”
SaveRef = doc.SaveRef(0)
Select Case SaveRef
Case “FirstApproverReject”
Msgbox “START - First Approver Reject”
emaildoc.form = “Memo”
emaildoc.from = “New”
emaildoc.subject = " Access Request"
emaildoc.Body = " Access Request has been Rejected"
Call emaildoc.send(False, email)
Msgbox “END - First Approver Reject”
Case “FirstApprove”
Msgbox “START - First Approve”
emaildoc.form = “Memo”
emaildoc.from = “New”
emaildoc.subject = " Access Request"
emaildoc.Body = "(user email) "
Call emaildoc.send(False, email)
'******* just create emaildoc again to send another email
set emaildoc = db.createdocument
emaildoc.form = “Memo”
emaildoc.from = "New "
emaildoc.subject = " Access Request"
emaildoc.Body = " Approver"
Call emaildoc.send(False, FirstApproverEmail)
Msgbox “END - First Approve”
Case “FinalApprove”
Msgbox “START - Final Approve”
emaildoc.form = “Memo”
emaildoc.from = "New "
emaildoc.subject = " Access Request"
emaildoc.Body = " Access Request is now complete (user email) "
Call emaildoc.send(False, email)
set emaildoc = db.createdocument
emaildoc.form = “Memo”
emaildoc.from = "New "
emaildoc.subject = " Access Request"
emaildoc.Body = “Team”
Call emaildoc.send(False,Team)
Msgbox “END - Final Approve”
End Select
End Sub