Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Object Variable not set when trying to run an agent

I have a project form that when saving it (action button), I would like it to send of some email notifications. I have the code below and I thought I could put the emails in to different agents and then call the agents into the script to run, but I keep getting a Object Variable not Set in the debugger on the line: Set agent1 = db.GetAgent ("Parent Update")

Sub Click(Source As Button)
	Dim s As NotesSession
	Dim agent1 As NotesAgent
	Dim agent2 As NotesAgent
	Dim agent3 As NotesAgent
	Dim db As NotesDatabase
	Dim ws As NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument
	Dim edoc As NotesDocument
	Dim rtitem As NotesRichTextItem
	Dim userName As NotesName
	
                     Set s = New NotesSession
	Set agent1 = db.GetAgent ("Parent Update")
	Set agent2 = db.GetAgent ("Sponsor Change")
	Set agent3 = db.GetAgent ("Documentor Assigned")
	Set db = s.CurrentDatabase
	Set ws = New NotesUIWorkspace
	Set uidoc = ws.CurrentDocument
	Set edoc = New NotesDocument(db)
	Set rtitem = New NotesRichTextItem(edoc, "Body")
	Set userName = s.CreateName(s.UserName)
	'Set uidoc = ws.EditDocument( True )
	uidoc.EditMode = True
	Set doc = uidoc.Document
 
	doc.Mod_Status = "Saved Project"
	doc.BP_Status="Pending BP Documents"
	Set item = doc.GetFirstItem( "Person" )
	Call item.AppendToTextList( s.CommonUserName )
	Set item = doc.GetFirstItem( "ActionDate" )
	Call item.AppendToTextList (Date$ + " " + Time$)
	Set item = doc.GetFirstItem( "Action" )
	Call item.AppendToTextList( "Assigned BP Documentor" )
 
	If doc.Parent(0)="Yes" And doc.notified(0)= "" Then
	Call agent1.Run
	End If
	
	If doc.IBT_Sponsor(0)<> doc.disp_Sponsor(0) Then
	Call agent2.run
	End If
	
	If doc.BP_Status(0) <> "Pending BP Docs" & doc.BP_Documentor(0) <>"" Then
	Call agent3.run
	End If
	
	Call uidoc.Save
	Call uidoc.Close
End Sub

Open in new window

0
kali958
Asked:
kali958
1 Solution
 
Bill-HansonCommented:
That message means that the db handle is not available.

You are calling db.GetAgent before db is set.

        Set agent1 = db.GetAgent ("Parent Update")
        Set agent2 = db.GetAgent ("Sponsor Change")
        Set agent3 = db.GetAgent ("Documentor Assigned")
        Set db = s.CurrentDatabase

If you re-write like this, it should work.

        Set db = s.CurrentDatabase
        Set agent1 = db.GetAgent ("Parent Update")
        Set agent2 = db.GetAgent ("Sponsor Change")
        Set agent3 = db.GetAgent ("Documentor Assigned")
0
 
kali958Author Commented:
Thank you - that was the problem!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now