Problem with Web Agent

I’m running into a problem with an agent I created. This agent basically takes the information from a form and sends it in an email after it is saved. I have the form and agent working on the client, however after throwing in some error trapping, I noticed that the agent for some reason isn’t processing right on the web. I’m creating a Nab view to pull the email addresses of where the email should be sent, based on a field chosen in this form, however based on the error trapping I put in, it’s not even finding the view or matching the keyword to the view. Here’s the agent. I’d greatly appreciate any help!

Sub Initialize( )

Dim session As New NotesSession

Dim db As NotesDatabase

Dim mailDoc As NotesDocument

Dim nameItem As NotesItem

Dim doc As NotesDocument

Dim lookupStr As String

Dim nabDb As NotesDatabase, nabView As NotesView

Dim nabDoc As NotesDocument

Dim FormName, FromName As String

Dim SubjectName, SendToName As String

Dim nam As NotesName, nameStr As String

Dim CopyToName As String

Dim rtItem As NotesRichTextItem



Set doc = session.DocumentContext

lookupStr = doc.GetItemValue("applications")(0)



Set nabDb = session.CurrentDatabase

Set nabView = nabDb.GetView("(AppData)")



Set nabDoc = nabView.GetDocumentByKey(lookupStr)

If Not(nabDoc Is Nothing) Then

	Set nameItem = nabDoc.GetFirstItem("manager")

	'Set nam = nameItem.Values("manager")

	Forall x In nameItem.Values

		nameStr = Cstr(x)

	End Forall

	Set nam = session.CreateName(nameStr)

	

	If doc.GetItemValue("status")(0) = "New" Then

		FormName = "Memo"

		FromName = doc.GetItemValue("filed_by")(0)

		SubjectName = "New Access Change"

		SendToName = nam.Common

		

		

		Set db = session.CurrentDatabase

		Set mailDoc = db.CreateDocument

		Set rtItem =mailDoc .CreateRichTextItem("Body")

		With rtItem

			Call .AppendText("There is a system access change request.")			

			Call .AddNewline(2)

			Call .AppendText(doc.filed_by(0) + " filed the following system access change: " + doc.change(0))

			Call .AddNewLine(2)

			Call .AppendText("Employee: " + doc.employee(0))

			Call .AddNewline(2)

			Call .AppendText("Application: " + doc.applications(0))

		End With

		

		With mailDoc

			.Form = FormName

			.From = FromName

			.Subject = SubjectName

			.SendTo = SendToName	

			.Send(False)

		End With



	Else



		FormName = "Memo"

		FromName = "Mark Rankin"

		SubjectName =  " Access Change Update For: " + doc.GetItemValue("employee")(0)

		SendToName = doc.GetItemValue("filed_by")(0)

		CopyToName = nam.Common

		

		

		Set db = session.CurrentDatabase

		Set mailDoc = db.CreateDocument

		Set rtItem =mailDoc .CreateRichTextItem("Body")

		With rtItem

			Call .AppendText("The following system access change request has been completed.")			

			Call .AddNewline(2)

			Call .AppendText("Access Change: " + doc.change(0))

			Call .AddNewLine(2)

			Call .AppendText("Employee: " + doc.employee(0))

			Call .AddNewline(2)

			Call .AppendText("Application: " + doc.applications(0))

		End With

		

		With mailDoc

			.Form = FormName

			.From = FromName

			.Subject = SubjectName

			.SendTo = SendToName	

			.CopyTo = CopyToName

			.Send(False)

		End With

	End If



Else

	Set db = session.CurrentDatabase

	Set mailDoc = db.CreateDocument

	Set rtItem =mailDoc .CreateRichTextItem("Body")

	With rtItem

		Call .AppendText("There is a error with system access change request application.")			

		Call .AddNewline(2)

	End With

	

	With mailDoc

		.Form = "Memo"

		.From = "mrankin@rpminc.com"

		.Subject = "Error"

		.SendTo = "mrankin@rpminc.com"	

		.Send(False)

	End With

End If

End Sub

Subject: Problem with Web Agent

Are NabDb and DB supposed to be getting set to the same database? It looks like you are getting the same database three times … is it getting the correct database for that view?

Subject: Problem with Web Agent

How are you calling/processing the agent? remember that you cannot use QuerySave or Postsave events on the web. You either have to call the agent from the WebQuerySave event or as a scheduled agent. I recommend the latter so web performance is not impacted.

Subject: Problem with Web Agent

I see a problem here that your “NabDB” and your DB are both being set to Session.CurrentDatabase.

I have a feeling that you want your NabDB to bet set to something else like:

Set NabDB = New NotesDatabase(“names.nsf”) (I’m guessing that by “nab” you’re talking about a Name & Address Book / Domino Directory.)

If you’re looking for a view that doesn’t exist…then you’re going to have an undefined object.