XML Agent not working

Here’s the code for my agent:--------------------------------------------------------------------------

Sub Initialize

Dim s As New NotesSession

Dim doc As NotesDocument

Dim searchDoc As NotesDocument

Dim db As NotesDatabase

Dim view As NotesView

Dim result As String



Set db = s.currentdatabase



Set doc = s.DocumentContext



key = doc.Query_string(0)



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

Call view.Refresh



For i = 1 To view.EntryCount

	Set searchDoc = view.getNthDocument(i)

	If searchDoc.form = "Company" Then

		If searchDoc.Unique = key Then

			result = searchDoc.Number(0)

			Exit For

		End If

	End If		

Next



Print "Content-type: text/xml"

Print "<results>"

Print "<number>"+result+"</number>"

Print "</results>"

End Sub


The problem is the agent seems to not print anything since on the browser the response xml is null.

Is there something my tired eyes are missing in this?

Here’s my Javascript on the browser-side.


//calls server and processes result

function getUnique(key, objID) {

obj = document.getElementById(objID);

xmlhttp.open(“GET”, “/form.nsf/DBLookup?OpenAgent&key=” + key);

xmlhttp.onreadystatechange = function() {

if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

  var xmlDoc = xmlhttp.responseXML;

  updateDocument( xmlDoc );

}

else {

  alert(xmlhttp.status);

}

}

xmlhttp.send(null);

}

//updates form

function updateDocument( xmlDoc ) {

var data = xmlDoc.getElementsByTagName( ‘result’ );

obj.value = getElementValue( data, “number” );

}

//reads the xml response

function getElementValue( xmlData, elementName ) {

var childElement = xmlData[0].getElementsByTagName( elementName )[0].firstChild;

if( childElement ) {

return childElement.nodeValue;

}

return “”;

}


Subject: XML Agent not working

The Query_string field will contain:

“OpenAgent&key=somevalue”

You need to take StrRight(key, “key=”) at the very least to get the actual lookup key. And doing an actual lookup (GetDocumentByKey) in a view designed for the lookup will be a lot less expensive than walking a view and opening every document until you find one that matches.

Subject: RE: XML Agent not working

Thanks a bunch

I figured it was something simple that I was overlooking.

and good idea about using getdocbykey, it’s so much easier and faster.