Agent.run is not working as I want it too

All,

I have the following code in a button click that based on a number on the form in database A,

Selects a view and a document in database B.

I have this working fine. If I do a: Call w.EditDocument(True, doc) then the correct document will open up in database B.

However, I don’t want to open the document, instead I want to run an agent in that database which will send mail.

The agent to create the mail is set to: Agent List Selection, with a Target of None, the name of the code is (CSRMailSendLS)

That code looks like this (“Body” field is a RT with a table in it):

FIELD PubTDS:= PubTDS;

@MailSend(PubTDS;“Teri Colvin”;“”;"This is a test mail from the Pub button, new MDP form for: " + TechRel_1 + ECRNumLkup;"Please review the Literature for this project: " + TechRel_1 + ECRNumLkup ;“Body”);

@All

The code that calls the above code:

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim db As NotesDatabase

Dim db2 As NotesDatabase

Dim doc As NotesDocument

Dim view As NotesView

Dim key As String

Dim uidoc As NotesUIDocument



Set uidoc = workspace.CurrentDocument 

key = uidoc.FieldGetText( "Prefix") + uidoc.FieldGetText( "ECRNum")



Set db2 = session.GetDatabase("Edison/SEL","MfgDevPlan.nsf") 

Set view = db2.GetView( "(MDPPubLkup)" )  

Set doc = view.GetDocumentByKey(key , True )



Dim ECRNumLkup As NotesItem

Dim agent As NotesAgent



If doc Is Nothing Then  'check is there an MDP in the database? if not stop

	Messagebox "No such document in MDP database."

	Exit Sub

Else

	Dim item As Variant

	item = doc.GetItemValue( "ECRNumLkup" )

	Set agent = db2.GetAgent("(CSRMailSendLS)")

	Messagebox "OK so here is what you are looking for in the MDP database  " + item(0),,"Hi Teri"

	If agent.Run = 0 Then

		Call agent.run

		Messagebox "Agent ran",, "Success"

		

	Else

		Messagebox "Agent did not run",, "Failure"

	End If

	

	Exit Sub

	

End If


The above code once clicked, produces the messagebox below with the correct number.

Messagebox "OK so here is what you are looking for in the MDP database " + item(0),“Hi Teri”

It then gives me the Messagebox “Agent ran”, “Success”

However, the problem is that I am not getting mail. I have made sure that my name is in the mailsend code.

Thanks in advance for any help you can give me.

Teri

Subject: agent.run is not working as I want it too…

What does the agent log of the target agent say? To see it: go to the design of the target database, select the agent and press right mouse button and select Log.

Subject: RE: agent.run is not working as I want it too…

Rob,

This is what the log states:

Started running agent ‘CSRMailSendLS’ on 10/21/2008 07:25:05 AM

0 document(s) were modified by formula

Done running agent ‘CSRMailSendLS’ on 10/21/2008 07:25:05 AM

Does that mean I really don’t have the document selected in the view as I thought so it is being called but not acted upon? I have tried selecting then running with the: Modify Documents selected, the Create New Documents Selected, and Selected Documents in View.

I have tried running the agent just on the view level and it ran fine.

Thanks what else would you like me to look at?

More Information:

I just changed the agent that I am calling to hard code in my name instead of looking up the field and it ran, but did not copy in the Body field as writtern.

So, agent will run, it just will not pick up the fields of the selected document. How do I get the LS agent calling this one to get focus on the document, to enable it to run this agent? Unless it is a completely diffferent issue that I am not aware of :slight_smile:

Teri

Subject: RE: agent.run is not working as I want it too…

Teri,

Are you able to send mail from the location where you run your agent?

Rob

Subject: RE: agent.run is not working as I want it too…

Yes I can send mail from the first database. I had thought about just running a mailsend from there with dblookups, but I need to copy the table from the Body of the form in the second database.

After the testing yesterday, it looks more and more like I can’t grab the data from the document I selected in the second document and place that in my called agent which sends the mail.

I found that if I can open the document in database 2 and send a memo from there fine, but I don’t like that the user will see that open document for a few seconds before the window closes.

What else would you like me to look at?

Thanks

Teri

Subject: RE: agent.run is not working as I want it too…

Teri,

Because you are saying that is looks like you cannot grab the data, I suspect that you are accessing a richtext field via the backend and that is always a source of problems.

what will happen when you rewrite your agent to lotusscript? You will probably be better off getting the information. And you would be able to add debug info. whenyou use print statements you will be able to check the server log to follow the flow and data of your agent better.

Rob

Subject: RE: agent.run is not working as I want it too…

Rob,

Your correct the mailsend is trying to load a RTField. I re-wrote the origninal LS to include a mailsend, see code below.

However, this code opens the selected form in the second database, sends the mail and closes the form. I just would prefer that the user did not see this action.

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim db As NotesDatabase

Dim doc As NotesDocument



Dim view As NotesView

Dim key As String

Dim uidoc As NotesUIDocument



Dim MDPdb As NotesDatabase

Dim MDPview As NotesView



'#####################################################

'Collect the number from the current document

'#####################################################

Set uidoc = workspace.CurrentDocument 

key = uidoc.FieldGetText( "Prefix") + uidoc.FieldGetText( "ECRNum")



'#####################################################

'Find second DB and matching doc, then send agent

'#####################################################

Dim w As New NotesUIWorkspace

Dim rtitemA As Variant



Set w = New NotesUIWorkspace

Set db2 = session.GetDatabase("Edison/SEL","MfgDevPlan.nsf") 

Set view = db2.GetView( "(MDPPubLkup)" )  

Set doc = view.GetDocumentByKey(key , True )



Dim ECRNumLkup As NotesItem



If doc Is Nothing Then  'check is there an MDP in the database? if not stop

	Messagebox "No such document in MDP database."

	Exit Sub

Else

	

	Call w.EditDocument(True, doc)

	Set uidoc2 = w.CurrentDocument    'this is the MDP doc

	Set ECRNumLkup = doc.GetFirstItem( "ECRNumLkup" )

	Set PubTDS = doc.GetFirstItem( "PubTDS" )

	Set rtitemA = doc.GetFirstItem( "Body" ) 

	

	Call uidoc2.Save   

	

	Dim senddoc As NotesDocument

	Dim db3 As NotesDatabase

	Set db3 = session.CurrentDatabase

	Set senddoc = New NotesDocument (db3)    'this is the memo being sent

	

	senddoc.SendTo = uidoc2.FieldGetText( "PubTDS" )   

	senddoc.CopyTo = ("Teri Colvin")

	senddoc.Form="Memo"

	senddoc.Subject = "Testing CSR send:  " + uidoc2.FieldGetText("ECRNumLkup")

	

	Dim rtitem As New NotesRichTextItem  (senddoc, "Body")  

	Set rtitem = New NotesRichTextItem    (senddoc,"Body")

	

	Call rtitem.AppendText("Hi all is this working??????" )

	Call rtitem.AddNewline(2)

	Call rtitem.addnewline(1)

	

	If ( rtitemA.Type = RICHTEXT And _

	rtitem.Type = RICHTEXT ) Then

		Call rtitem.AppendRTItem(rtitemA)  

	End If

	

	Call senddoc.Save (False, True)

	Call senddoc.Send( True ) 

	Call uidoc2.Save

	

	

End If



	'******************************************************************************************

doc.SaveOptions = "0" 

Call uidoc2.close

How can I change this so that I don’t have to open the doc to get the RTField information in the “Body” field?

Thanks

Teri