How Can I call a LS agent from a Javascript function?

I have a form which uses JS validation in a function. If the funtion passes validation, I want to call my lotusscript agent which sends an e-mail and saves the document using a new form. How can I call my agent using javascript?

Subject: How Can I call a LS agent from a Javascript function?

I call LS from JavaScript by creating a button on the form that kicks off an LS agent, then I call the button from JavaScript with a .click() call. It’s very easy, and onLoad always runs afterwards, allowing me to check fields that were set by LS.

Subject: How Can I call a LS agent from a Javascript function?

Make the agent a WebQuerySave agent and simply submit the form.

Subject: RE: How Can I call a LS agent from a Javascript function?

I should have mentioned that I don’t always want the agent to run. Only if the form passes validation. I’m finding that if I use a WQS agent, it is running even if my validate function returns false. Is there a way not to submit the form? I have posted the call to the function below. using the alert, I have verified that if there is an error the return is false. However, the form is still submitted (calling the wqs agent).

var t = validate(frm);

window.alert(t)

if (t = “true”){

//run the agent by submitting the form

frm.submit();

}else{

//do nothing. Will want to move the popups here eventually to specify the error which occurred and move to that field.

//window.alert(“not valid”);

}

Subject: Probably because validate(frm) returns a boolean not a string…

Try:var t = validate(frm);

window.alert(t)

if (t){

//run the agent by submitting the form

frm.submit();

}else{

//do nothing. Will want to move the popups here eventually to specify the error which occurred and move to that field.

//window.alert(“not valid”);

}

Subject: RE: Probably because validate(frm) returns a boolean not a string…

Yep, that was it. Duh. Thanks.

Subject: RE: Probably because validate(frm) returns a boolean not a string…

And on top of that it was an assignment, not a comparision. Should be ==, not =. The assignment was always true.

Subject: RE: How Can I call a LS agent from a Javascript function?

If you don’t want to post the form for whatever reason, you can also just call the agent directly in the URL as in the following code snippet:

function setReportLocation(strQueryName, strStartDate, strEndDate) {

var blnValidDateRange = testDateRange(strStartDate, strEndDate);

if (blnValidDateRange == false) {

	frm.StartDate.focus();

}

else {

	location = "./ReportWriter?OpenAgent&Q=" + strQueryName + "&SD=" + strStartDate + "&ED=" + strEndDate;

}

}

This is used for a report where I have a start date and end date field the user fills out and I have to validate they entered a valid date range before submitting the report request. Since this is a portal form that serves many different reports and then has a dedicated post action I don’t want to bog down the WQS agent with dealing with report redirection also so I just set the location directly once I have validated that I can sucessfully submit required parameters to the report agent.

Subject: How Can I call a LS agent from a Javascript function?

FYI:The agent code is appended below. It is very simple. I will need to be able to pass information from the current document into the agent using the document context.

Sub Initialize

Print |<SCRIPT LANGUAGE=JavaScript>window.alert('Starting up... ')</SCRIPT>|		

Dim s As New notessession

Dim db As notesdatabase

Dim doc As notesdocument



Set db = s.CurrentDatabase

Set doc = s.DocumentContext



path=db.FilePath



doc.form = "ComplaintNotes"



Call doc.ComputeWithForm(True, False)

Call doc.Save(True, False)

'Send the document here or an e-mail with a doclink to the actual document in the database.

Call doc.Send(True, sendto)

doc.form="Complaint"

Call doc.ComputeWithForm(True, False)

Call doc.save(True, False)



Print "[/" + path + "/(all)/" + doc.UniversalID + "?OpenDocument]"

’ Print “[/” + path + “/(all)/” + “?openview]”’ “?opendatabase]”

End Sub