Web agent prints html instead of xml

I have an agent that should return results in xml format.

Instead it prints the following:

Agent done

my agent’s code is below:


Sub Initialize

Dim s As New NotesSession

Dim doc As NotesDocument

Dim searchDoc As NotesDocument

Dim docCollection As NotesDocumentCollection

Dim db As NotesDatabase

Dim view As NotesView



Set db = s.currentdatabase



Set doc = s.DocumentContext



query = doc.Query_string(0)

key = Strright(query, "=")



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

Call view.Refresh



Set docCollection = view.GetAllDocumentsByKey(key)	



Set searchDoc = docCollection.GetFirstDocument



    Print "Content-type: text/xml"

Print "<results>"



'Loop as long as there are document objects available.	

While Not ( searchDoc Is Nothing )

	Print "<quantity>"+searchDoc.item+"</quantity>"

	Set searchDoc = docCollection.GetNextDocument(searchDoc)

Wend



Print "<key>"+key+"</key>"	

Print "</results>"

End Sub


I’ve even tried commenting out everything save storing the query and print commands and it still doesn’t work.

here’s how I call the agent:

xmlhttp.open(“GET”, “/Form.nsf/SearchAgent?OpenAgent&key=” + key); //calls agent

Subject: Web agent prints html instead of xml

You have a couple of spots where the agent could fail BEFORE you print the content-type, and you aren’t trapping any errors. There is a chance that both the document collection and its first document could be Nothing.

Subject: RE: Web agent prints html instead of xml

The problem with that is if I comment everything out but:

Dim s As New NotesSession

Dim doc As NotesDocument

Dim searchDoc As NotesDocument

Dim docCollection As NotesDocumentCollection

Dim db As NotesDatabase

Dim view As NotesView

Set db = s.currentdatabase

Set doc = s.DocumentContext

query = doc.Query_string(0)

key = strRight(query, “=”)

Print “Content-type: text/xml”

Print “”

Print “”+key+“”

Print “”

I still get the html response.

I’m thinking it’s something with the properties of the agent, but even that’s set-up to match a similar agent that works. I’m absolutely lost on what the problem is.

Subject: RE: Web agent prints html instead of xml

While this is surprising indeed, Stan’s answer still applies: If the agent returns Domino’s generic Agent done message (and that’s what you get), it means that the agent doesn’t get to the print statements (for whatever reason).

Add some error reporting code (possibly using OpenLog, or at least writing messageboxes to the server log) or use the remote debugger.

Subject: RE: Web agent prints html instead of xml

Thanks for the suggestion with using msgboxes to send to the log, I didn’t know that’s where they go.

As of yet, I haven’t solved the problem, but at least I’m on it’s trail.

Seems to be a type mismatch.

Subject: RE: Web agent prints html instead of xml

One more note: I don’t know how closely the code you posted resembles the code you are really running or how much you stripped off for clarity, but: No matter what you do, ALWAYS use Option Declare in your code to minimize avoidable runtime errors.

Subject: Web agent prints html instead of xml

try thisPrint “Content-type: text/xmldom”