How do I run an Agent from JavaScript

I have a piece of Javascript. I wish to call an Agent from this piece of code. Does anyone know the syntax for this ?

Thanks

Subject: RE: How do I run an Agent from JavaScript

You can try something like:

window.location = http://server/xyz.nsf/AgentName?OpenAgent’;

If the agent needs and additional parameters (such as the docID), you can pass in them in as part of the query string.

http://server/xyz.nsf/AgentName?OpenAgent&Foo=123&Bar=abc

(Your agent can parse the values out of the query string)

HTH…

Subject: RE: How do I run an Agent from JavaScript

Will give this a try

Thanks for your help

Vic

Subject: How do I run an Agent from JavaScript

  1. Type a text like: and set it Path-Thru HTML. This will make current hotspot invisible for the web page, but still available for javascript.2. Select the text and Create–>Hotspot–>Action Hotspot…

  2. In action properties box go to last tab () and set Id to AgentCaller

  3. Set action hotspot formula to @Command([ToolsRunMacro];“”)

  4. To call agent from javascript use command AgentCaller.click()

P/S: In some cases preferable to use document.all[“AgentCaller”].click() command to call the agent instead command in step 5 (IE syntax)

Best Regards,

Dima Pechersky

Subject: RE: How do I run an Agent from JavaScript

Wow, what a great post!

Subject: RE: How do I run an Agent from JavaScript

Thanks Becca

Subject: RE: How do I run an Agent from JavaScript

Hi There,

I tried your solution, but could not make it work. I am having custom login form, and session authentication is activated. I have a Javascript on a Login Button in that form, and also I want to run this agent, Will you please guide me, where am I going wrong?

I have an agent which has following code,

Sub Initialize

Dim doc1 As NotesDocument	

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument		

Dim user As String



Set doc1 = session.DocumentContext

Set db = session.GetDatabase("", "db1.nsf")		

Set view = db.GetView ("(LookupView)" )

user = doc1.Username(0)	

Set doc = view.GetDocumentByKey (user )	

If Not (doc Is Nothing) Then

	Call doc.ReplaceItemValue ( "LoggedDate", Today )		

	Call doc.Save(True, True)

End If

End Sub

Thanks

MS

Subject: RE: How do I run an Agent from JavaScript

Hi Manish,

My solution is good for callig agent with JavaScript. It’s doesn’t matter what your agent going to perform. The point it’s to connect between JavaScript and Lotus Script agent.

Your agent look absolutely correctly written. If you could supply me more information i will glad to help you.

Best Regards,

Dima Pechersky

Subject: RE: How do I run an Agent from JavaScript

Hi Dima,

Thanks for this post. One question though. With this method, can you pass any parameters and if so, how?

Thanks,

Patti

Subject: RE: How do I run an Agent from JavaScript

When you call an agent via @command([toolsrun macro]) the document is submitted and passed to the agent. The agent can access it via session.documentcontext. It can read all notes fields and if required modify them. When the agent is finished the document is returned to the browser. So you don’t need parameters. The required info must just be stored somewhere in the document.

Subject: RE: How do I run an Agent from JavaScript

Hi Dima, You idea is great, but when I try to put it in practice, I faced some problem on it, maybe I missed some points.

When I created a text <!-- AGENT --> in a form, make it pass-thru html, fill in ID and assign action hotspot to it, it only displays the text <!--AGENT--> which is hidden from page but doesn't generate the hidden object id as desired.

Instead, if it does not make it a pass-thru html, a link is generated like this

<!-- AGENT –>

and it can be called by the javascript AgentCaller.click().

Is there any means to hide the link from browser for this case ?

Thank you.

Subject: RE: How do I run an Agent from JavaScript

Hi,

is comments tag. It contant will be invisible. It's like to create hotspot without text. But in this way is difficult to maintain it.

So I prefer this method to create invisible hotspot but it still available thru javascript document object model

Best Regards,

Dima Pechersky

Subject: RE: How do I run an Agent from JavaScript

hican anybody explain stuff bcoz i tried using the way but it says me

AgentCaller undefined although i made it as its id n followed the procedure Dima mentioned

thanks in advance

Best Regards

Subject: RE: How do I run an Agent from JavaScript

Ok Guys,

I got the problem! I think that reason is browser and operation system compatibilities, but never mind…

Calling agent AgentCaller.click() could make the problem in some cases.

Same result could be get with this code:

document.all[“AgentCaller”].click() (IE syntax)

I updated original topic too

Best Regards,

Dima Pechersky

Subject: RE: How do I run an Agent from JavaScript

I’m getting Javascript error for document.all[“AgentCaller”].click(). Please help.

Error ToObjectError: document.all has no properties.

Subject: RE: How do I run an Agent from JavaScript

You’re not using Internet Explorer, are you? Nobody should ever, for any reason, use, or encourage others to use document.all. It is an IE-only collection, and a significant number of people don’t use IE.

Now, if you want to put an invisible clickable button on your page, DON’T use HTML comments to hide it. When it has comments around it, it is not an active part of the document, and cannot be clicked in any browser that is working properly.

Create the hotspot or button on the form,and go to the tab of the properties for that button. Give it an ID (one word, no spaces or punctuation). In the Style slot, put this:

display: block; position: absolute; top: 0; left: 0; margin: -100px 0 0 -100px; visibility: hidden

That moves the button off-screen to the top and left, and also makes it invisible (just in case). Now, you just need to click it:

document.getElementById(‘theIdYouCreatedGoesHere’).click()

Subject: RE: How do I run an Agent from JavaScript

Sorry for not being clear on my question before.

Actually I’m trying to run the agent using javascript from a action Button on notes client. I want this to run on the notes client only.

Please help.

=======================================

I’m getting Javascript error for document.all[“AgentCaller”].click(). Please help.

Error ToObjectError: document.all has no properties

Subject: RE: How do I run an Agent from JavaScript

That’s because document.all ONLY works in Internet Explorer. Unfortunately the Notes client doesn’t do getElementById, but it DOES do document.forms[0].elements[‘ButtonHTMLName’].click(). As long as the button has a name, you can click it in Notes that way – but since you’re in Notes, that raises the question, WHY? Using Formula or LotusScript and running the agent directly from whatever event you’re in would make a LOT more sense.

Subject: RE: How do I run an Agent from JavaScript

Actually I’m having some field validations ( which can have both date and specific string/text format). For this validations I’m using javascript thinking that this would be easy.

If I using formula to run the agent, these validation are triggered, still the agent is processing. So thought would first validate the stuff and the run the agent using Javascript.

Thanks Roger , i WILL TRY THIS THEN.

Subject: RE: How do I run an Agent from JavaScript

Sorry Rogers to Bug you,

Still I get the Javascript error for the code below.

document.forms[0].elements[‘AgentCall’].click(). I have the AgentCall as the Hotspot action Button. In the HTMLTag name is AgentCall.

Error:ToObjectError: document.forms[0].elements[“AgentCall”] has no properties.