Tip

Extracting query string parameters in agents

This code will produce a LotusScript list of key value pairs representing the query string passed to the agent in the form:-

http://server/db.nsf/agWeb?OpenAgent&Fred=Wilma&Barney=Betty&BedRock

The list will allow you to extract these parameters like this:

lstParams( "fred" )
IsElement( lstParams( "bedrock" ) )

The code uses the LotusScript Evaluate command to process the QUERY_STRING_DECODED and make it into an array. It is very simple to understand and because it uses the QUERY_STRING_DECODED there is no need to decode the string as Domino does this for us!

The keys for the list are converted to lowercase as it is easy to pass parameters that are in the wrong case. The case of the values is left unaltered.

To call the function, use the code in the Initialize sub.
Enjoy!

sub Initialize
	Dim session As New NotesSession
	Dim docCurrent As NotesDocument
	Dim lstParams As Variant
	
	lstParams = funGetQueryParameters( docCurrent.QUERY_STRING_DECODED(0) )
	
	Forall sValue In lstParams
		Print Listtag( sValue ) & "=" & sValue & "<br>"
	End Forall
End Sub

Function funGetQueryParameters( sQueryString As String ) As Variant
	
%REM

Given the QUERY_STRING_DECODED, return a string list containing key value pairs

%END REM
	
	Const FORMULA_EXPLODE_QS_1 = |@EXPLODE( "|
	Const FORMULA_EXPLODE_QS_2 = |";"&")|
	Const FORMULA_EXPLODE_PAIR_1 = |@EXPLODE( "|
	Const FORMULA_EXPLODE_PAIR_2 = |";"=")|
	
	Dim lstParams List As String
	Dim vAllPairs As Variant
	Dim vPair As Variant
	
	vAllPairs = Evaluate( FORMULA_EXPLODE_QS_1 & sQueryString & FORMULA_EXPLODE_QS_2 )
	
	Forall sPair In vAllPairs
		vPair = Evaluate( FORMULA_EXPLODE_PAIR_1 & sPair & 
FORMULA_EXPLODE_PAIR_2 ) 'The line below catches the situation where there is no
pairing, ie just a single 'key name with no value. In this case the key and value are the same lstParams( Lcase(vPair(0)) ) = vPair( Ubound( vPair ) ) End Forall funGetQueryParameters = lstParams End Function

This was first published in May 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.