Showing posts with label agent. Show all posts
Showing posts with label agent. Show all posts

Friday, July 27, 2007

Working around the 64k print limit in web-agents

In LS, there seems to be a 64k limit per Print statement

If you have agents that print a large amount of HTML/XML (concatenating into a string), one workaround is to check the string-length frequently:

If Len(yourString) > safeNumber Then
Print yourString
yourString = ""
End If

Where yourString is the string containing the HTML/XML/etc., and safeNumber is a number that is smaller than the 64k - the maximum amount of characters you can imagine is added per concatenation.

If there is A LOT (5000+) of string concatenation in the agent, I suggest using Julian Robichaux' StringBuffer class. You would have to add a getLength-method, to check the length of the buffer.

Something like this:

'in stringbuffer class
Public Function getLength() As Long
getLength = Len(buffer)
End Function

'in the printing agent
If bufferObject.getLength > safeNumber Then
Print bufferObject.toString()
bufferObject.erase()
End If


The above If-statements .. > safeNumber .. should be put inside the loop that you use to concatenate the string. Thanks for making me aware of the bad "documentation", Thomas.


If you have a lot of different content you want to print, I'd suggest having one agent per content-type, and that the agents only contains method calls to their respective script libraries (which in turn can use other scriptlibs). Having 20+ agents in an application quickly gets messy (at least from my point of view).

Example:
..xml?OpenAgent&action=report&type=wages&employeenum=2134212

In agent (untested code):

Use "PrintXML"
Dim s As New NotesSession
Dim action As Variant

action = Evaluate( |@UrlQueryString("action")|,_
s.DocumentContext)
'the evaluate above returns a text-list with one item
Select Case( action(0) )
Case "report"
Call report( s.DocumentContext )
End Select

64k limit on "Print" in web agents

I knew there was a limit, but I didn't take the time to test it before today.

According to my tests, the limit is 65 534 characters per Print statement. When the string you're printing is above this, something strange happens.

I made an agent with a For .. To loop to concatenate a string. The string contains the counter and a line-break per loop.

String length: 65 193
Last line printed: 5100 (Correct, For 1 To 5100)

String length: 70 393:
Last line printed: 414 (Wrong)

String length: 78 193
Last line printed: 1059 (Wrong)