Subject: Passing a value from a lotus notes agent back to javascript - you need AJAX
what you need to do is use AJAX!
Below is a very basic explanation of AJAX and Notes and then some sample code. Essentially you have an event which triggers some code in the JS header. This code then sends a URL back to notes with a variable attached to the end of the URL. Your lotusscript agent is then set in motion and uses the variable to do what you want. It then uses the print command to send a string back to the browser. More code in the JSHeader then ‘decodes’ whatever you have sent back and writes it to fields or whatever you want.
Cheers
Paul
1 - It starts with the onChange event of the something in the browser that then starts the callServer code.
callServer(this field name, this field selected option)
2 - This uses the callServer function in the JSHeader
// function to call the server
function callServer(fieldName,fieldValue)
{
// Build the URL to connect to
var url = “/xyz/xyzdir.nsf/Aagentname?OpenAgent&datastart=fieldname=” + fieldName + “fieldvalue=” + fieldValue + “dataend”;
// Open a connection to the server
xmlHttp.open(“GET”, url, true);
// Setup a function for the server to run when it’s done
xmlHttp.onreadystatechange = updatePage;
// Send the request
xmlHttp.send(null);
}
(which in turn uses the piece of code in the JSHeader)
// code to create the connection to the server, IE browsers only, errors on fail
var xmlHttp = false;
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2)
{
xmlHttp = false;
}
}
if (!xmlHttp)
{
alert(“Your Browser doesn’t meet IT requirements, please contact your local IT rep.”);
}
3 - This calls the LotusScript agent that does the donkey work and then prints the information back to the browser.
The start of your agent needs to be:
Sub Initialize
’ setup the session, get the document and return string variable
Dim session As New NotesSession
Dim strReturnResults As String
Dim doc As NotesDocument
Set doc = session.DocumentContext
and then the end of your agent needs to be:
’ write the results to the return string
strReturnResults = "datastart=" + ":fn:" + secondaryField + ":no:" + Trim(Str(secondaryVC.Count-secondaryDuplicates)) + ":fv:" + secondaryList + ":fn:" + tertiaryField + ":no:" + Trim(Str(tertiaryVcCount-tertiaryDuplicates)) + ":fv:" + tertiaryList + "dataend"
Print strReturnResults
End Sub
4 - The returning information is dealt with in the JSHeader
// function to deal with the results
function updatePage()
{
if (xmlHttp.readyState == 4)
{
var response = xmlHttp.responseText;
}
}