Many times when we do lotus domino development, we need to send parameters to the server. How do we do this? well using a url like this:
http://www.something.com/resource?command¶m1=val1¶m2=val2
If this is pointing to a form, then we all need to do is call:
@URLQueryString
But sometimes, we want to call an agent and do some processing there, in this case we can use the function below to parse the query_string field:
Plesea note, the way we get the query string in an agent would it be: session.documentcontext.query_string(0)
Function parseQS( queryString As String, params List As String ) As Integer
Dim buffer As Variant, pairs As Variant, ceiling As Integer, i As Integer
On Error Resume Next
Erase params
buffer = Split( queryString , "&" )
ceiling = Ubound( buffer )
For i=0 To ceiling
pairs= Split( buffer(i), "=" )
params( pairs(0) ) = pairs(1)
Next
parseQS = ceiling
End Function
The first parameter is the queryString field returned by Domino. The second is an output parameter, a list of strings, that will contain each name/value pair in query string. Additionally the function returns an integer with the number of elements in the result list.
Plese Note, that if this function is called more than once any previous list sent as a parameter, will be destroyed. Lastly the "Resume Next" make sure the function keeps running and returns as much values, in the list, as possible.
Also I came across this version of the similar program but in Java:
public static java.util.Hashtable parseQueryString(String queryString) {
StringTokenizer tokens = new StringTokenizer(queryString, "&");
Hashtable params = new Hashtable();
while (tokens.hasMoreTokens()){
String token = tokens.nextToken();
int equalIdx = token.indexOf('=');
if (equalIdx != -1 && !token.equalsIgnoreCase("OpenAgent")){
String name = token.substring(0, equalIdx);
String value = token.substring(equalIdx + 1);
params.put(name, value);
}
}
return params;
}
The java version use a StringTokenizer to parse the url and returns a HashTable. The way you invoke this function in java would be:
String qs= doc.getItemValueString("Query_String");
java.util.Hashtable ht = parseQueryString(qs);
String strUNID = (String) ht.get( "ID" );
Please Note you have to cast the value to String. The link where you can find a sample of this code is:
http://searchdomino.techtarget.com/tip/0,289483,sid4_gci1264609,00.html
In my next post will show you want way to redirect a request using a simple print in Lotus Script.