LotusScript agent fails with browser (web)

We’re trying to web-enable our Notes databases. The following is in a LotusScript agent that is called from a button on a form. It works fine when a Notes client is used, but nothing happens when a browser (IE) is used. I don’t know how to troubleshoot this without a script debugger. What’s in this code that would not work in a browser, and how do I work around it?

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim db As NotesDatabase

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim docMemo As NotesDocument

Dim lookupView As NotesView

Dim lookupDoc As NotesDocument

Set db = session.CurrentDatabase

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document

If Not doc.EmailSent(0) = “Yes” Then

Set docMemo = db.createdocument

docMemo.Form = "Memo"

Set rtitem = docMemo.CreateRichTextItem( "Body" )

Call rtitem.AppendText("Body text goes here.")



Set lookupView = db.GetView( "LookupContacts" )

Set lookupDoc = lookupView.GetDocumentByKey( "ChangeManager" )

docMemo.SendTo = lookupDoc.Contact

docMemo.Subject = "Subject line here."

End If

Call docMemo.Send( False )

doc.EmailSent = “Yes”

Subject: LotusScript agent fails with browser (web)

You agent doesn’t work on the Web because it uses UI classes.

Remove the lines:

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

and change

Set doc = uidoc.Document

to

Set doc = session.DocumentContext

Then your agent works both from Notes and Web.

Subject: RE: LotusScript agent fails with browser (web)

Thanks! That looked promising, but I still get the same result: It works in Notes, but not from a browser.

Is there any way I can debug this?

Subject: RE: LotusScript agent fails with browser (web)

You can debug on the web using error handling routines

On Error goto errorhandler

then at the end of your code add

Exit sub

errorhandler:

do whatever you want

End Sub

You can use msgbox which writes to the server console, print which writes to the browser, write to a notes log or send yourself an email all with the line and error code.

This line looks like an error to me

docMemo.SendTo = lookupDoc.Contact

Should be

docMemo.SendTo = lookupDoc.Contact(0)

Subject: RE: LotusScript agent fails with browser (web)

I’ve tried msgbox, print, and write – none of which work when in the browser.

I’ve tried adding the following to the beginning of the agent, just to see if it’s running…

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim errorMemo As NotesDocument

Set errorMemo = db.CreateDocument

errorMemo.SendTo = “My Name”

errorMemo.Subject = “Starting agent”

errorMemo.Send( False )

Nothing happens when run from a browser. So either it can’t get through the above few lines, or it’s not actually running at all.

Nothing shows on the server console when trying to run from a browser. Is there a separate agent log? How do I get to that?

Subject: RE: LotusScript agent fails with browser (web)

Right click on the agent in designer to get the agent log which will tell you the last time the agent ran.

The agent can not be running as both print and msgbox work in a webquerysave agent and there is nothing wrong with your email code so at the very least you should receive an email if the agent was running.

A couple of things to check are if the agent is signed by yourself do you have rights to run lotusscript agents on the server and also the agent selection criteria. Set it to run from Agent List selection with a target of none.

Another thing that may or may not be an issue as I have never tried to do it this way is the lines of code after you run the agent

@Command([FileSave]);

@URLOpen(“http://www.mydomain.com/” + @WebDbName + “/thankyou.html?OpenPage&OriginalTopicID=” + TopicID)

You can save the document in the webquerysave agent and then redirect the user to the url using the print statement

Subject: RE: LotusScript agent fails with browser (web)

The agent log indicates it IS running, but I still get nothing when triggered from a browser. (And it continues to work fine when run from a Notes client.) The agent is signed by me, and I have rights to run on the server. (My other script agents in this database work fine.)

It’s set to run from Agent List with a target of None.

Note that the commands after the agent call do work: The document saves and the redirection works fine. It’s just that this agent can’t seem to send any mail or generate any messages.

Subject: RE: LotusScript agent fails with browser (web)

After you have called your agent the formula will not wait until the webquerysave agent has completed to run your fileSave and UrlOpen

What I’m thinking which may be nonsense is that you start the agent but then the following formulas run which interrupt the agent causing it to stop running.

Test it out by commenting out these two lines so that you are only calling the agent and then add to your agent at the beginning.

Print “Agent is running”

Exit Sub

Subject: RE: LotusScript agent fails with browser (web)

I’ve tried removing the other lines so that only the agent is called, but got the same result.

BUT this is interesting. I changed the agent to this…

Print "In agent..."

Dim progress As Integer

progress = 0

Print progress

Dim session As New NotesSession

progress = 1

Print progress

Dim db As NotesDatabase

progress = 2

Print progress

Set db = session.CurrentDatabase

progress = 3

Print progress

Dim errorMemo As NotesDocument

progress = 4

Print progress

Set errorMemo = db.CreateDocument

progress = 5

Print progress	

errorMemo.Form = "Memo"

progress = 6

Print progress

errorMemo.SendTo = "myMailAddress"

progress = 7

Print progress

errorMemo.Subject = "Starting agent"

progress = 8

Print progress

errorMemo.Send( False )

progress = 9

Print progress

…and it prints up through 9 in both cases – triggered from a browser and triggered from a Notes client. However, I don’t get any mail when triggered from a browser.

Subject: RE: LotusScript agent fails with browser (web)

I have run this code in an agent called from the webquerysave event and receive an email and the following output

In agent… 0 1 2 3 4 5 6 7 8 9

I also tried adding the FileSave and URlOpen commands after calling the agent and found that they make no difference although the UrlOpen did not work. You do not need the FileSave as the document must already being saved for the webquerysave event to run and you can redirect the user in the agent - example below

Print {}

I would have thought that if your server was unable to send the email then it would throw an error and you would not get to the line where 9 is printed to the browser. Do you have other agents that send emails which run on the server Ok? If so then I have no idea what the problem is.

Subject: RE: LotusScript agent fails with browser (web)

“Contact” is a multi-value field and I want all the values, so wouldn’t I leave off the index? This works using a Notes client.

I’ve tried “On Error GoTo…,” but so far this has not told me anything when run in a browser. I’ll have to try different approaches with this tomorrow.

Subject: RE: LotusScript agent fails with browser (web)

Marc, how do you launch the agent from the web? You can’t use Notes Form methods (like QuerySave, PostOpen, etc…), but you can only use WebQuerySave and WebQueryOpen to call an LotusScript agent by Form actions. In addition you can also call an LotusScript agent from a button, but you can’t put the LotusScript code directly into the button, the agent must be called via @Command([ToolsRunMacro];“YourLotusScriptAgent”). The third option is to call the agent directly via URL, but in this case you probably don’t need that.

Subject: RE: LotusScript agent fails with browser (web)

The agent is called via a button using @Command([ToolsRunMacro];“(QuestionNotifications)”). After calling the agent, the doc is saved, the user is presented with a “thank you” page, and then redirected to where they were before submitting the question. Here’s the complete button code…

@Command([ToolsRunMacro]; “(QuestionNotifications)”);

@Command([FileSave]);

@URLOpen(“http://www.mydomain.com/” + @WebDbName + “/thankyou.html?OpenPage&OriginalTopicID=” + TopicID)

NOTE: It’s not literally “mydomain,” of course. :slight_smile:

Subject: RE: LotusScript agent fails with browser (web)

You should not use any other commands than the @Command([ToolsRunMacro];…). You can do the other commands from within the LotusScript agent, like saving the document and opening another URL.

Subject: LotusScript agent fails with browser (web)

Note: The default access for viewing and running is All readers and above. But I’ve also tried checking “Run as web user,” “Run on behalf of (me),” setting runtime security level to allow restricted operations with full admin rights, and checking “Allow Public Access users to view and run.”

None of these worked.