I write this code for tracking documents. But when I run manually, it is successfully run. But when I schedule to run the agent, there was an error “Agent execution time limit exceed”.
This is my code:
Sub Initialize
Print "Start"
Dim session As New NotesSession
Dim curdb As NotesDatabase
Dim setup_doc As NotesDocument
Dim setup_db As NotesDatabase
Dim setup_View As NotesView
Dim tracking_doc As NotesDocument
Dim tracking_db As NotesDatabase
Dim tracking_View As NotesView
Dim rtitem As NotesRichTextItem
Dim gacs_doc As NotesDocument
Dim gacs_db As NotesDatabase
Dim gacs_View As NotesView
Dim gacs_dc As NotesDocumentCollection
Dim cnName As NotesName
Dim slcted_doc As NotesDocument
Dim slcted_db As NotesDatabase
Dim slcted_View As NotesView
Dim slcted_dc As NotesDocumentCollection
Dim keyString(1) As String
Set curdb = session.CurrentDatabase
Set gacs_db = New NotesDatabase("SunwebA1/S/Sunway", "Ghr\ApprCtrl.nsf")
Set setup_View = curdb.GetView("svAppsSetup")
'Set gacs_View = gacs_db.GetView("MainICNameTrackingStaff")
'Set gacs_doc = gacs_View.Getfirstdocument
Set setup_doc = setup_View.GetFirstDocument
recNo = 0
While Not setup_doc Is Nothing
dbServer = setup_doc.GetItemValue("dbServer")(0)
dbPath = setup_doc.GetItemValue("dbPath")(0)
Set slcted_db = session.GetDatabase(dbServer, dbPath, False )
Set slcted_View = slcted_db.GetView(setup_doc.GetItemValue("ViewName")(0))
Forall sStatus In setup_doc.Status
Set gacs_View = gacs_db.GetView("MainICNameTrackingStaff")
Set gacs_doc = gacs_View.Getfirstdocument
While Not gacs_doc Is Nothing
recNo = recNo + 1
sName = gacs_doc.empname(0)
Set cnName = New NotesName(sName)
'Print Str(recNo)
keyString(0) = sStatus
keyString(1) = cnName.Common
Set slcted_dc = slcted_View.GetAllDocumentsByKey(keyString)
Set slcted_doc = slcted_dc.GetFirstDocument
'Print setup_doc.dbpath(0) + " - " + sStatus + " - " + setup_doc.FormName(0) + " - " +setup_doc.FormApproverNm(0) + " - " + cnName.Common + " - " + Cstr(slcted_dc.count)
While Not (slcted_doc Is Nothing)
'If Not setup_doc Is Nothing Then
'Print slcted_doc.GetItemValue(setup_doc.GetItemValue("FormApproverNm")(0))(0) + "=" + cnName.Common
If slcted_doc.GetItemValue(setup_doc.GetItemValue("FormApproverNm")(0))(0) = cnName.Common Then
Set tracking_doc = New NotesDocument(curdb)
tracking_doc.Form = "dfApprover"
tracking_doc.appsTitle = setup_doc.AppsTitle
tracking_doc.txtDocStatus = sStatus
tracking_doc.txtFormNm = setup_doc.FormName
tracking_doc.txtCategory = setup_doc.slcCategory
tracking_doc.dbServer = setup_doc.dbServer
tracking_doc.dbPath = setup_doc.dbPath
tracking_doc.docCat = setup_doc.slcCategory
tracking_doc.docType = setup_doc.slcType
tracking_doc.BU = setup_doc.slcBUGrp
tracking_doc.txtStaffName = cnName.Common
tracking_doc.ViewName = setup_doc.GetItemValue("ViewName")(0)
tracking_doc.StsFieldNm = setup_doc.GetItemValue("FormFieldStatusNm")(0)
Set rtitem = tracking_doc.CreateRichTextItem ("DocLink")
Call rtitem.AppendDocLink (slcted_doc, "" )
Call tracking_doc.Save(True, False)
End If
Set slcted_doc = slcted_dc.GetNextDocument(slcted_doc )
Wend
Set gacs_doc = gacs_View.GetNextDocument(gacs_doc )
'Set gacs_doc = gacs_View.GetNthDocument(gacs_doc )
Wend
Set setup_doc = setup_View.GetNextDocument(setup_doc )
'Set setup_doc = setup_View.GetNthDocument(setup_doc )
End Forall
Wend
Print "Completed"
End Sub
Please helppp