Reading QueryString easier

Reading QueryString easier

Function getArgumentValue() can be used in LotusScript Web agents to parse argument values from QueryString. Function recognizes both arguments with an assigned value (like ProdID=123456) and also arguments without a value (like ShowStat).

Rules:
If argument is not present in QueryString, function returns an empty string. If argument with assigned value is present, it returns its value. If argument without assigned value is present, it returns "1".

Code: Function getArgumentValue(queryString As String, argName As String) As String
	Dim delimiter As String, qs As String, pos As Integer
	Dim posVal As Integer, partR As String
	delimiter = "&"
	qs = delimiter + queryString + delimiter
	pos = Instr(1, qs, delimiter + argName + "=", 1)
	If pos > 0 Then
		partR = Right(qs, Len(qs) - (pos + 1 + Len(argName)))
		getArgumentValue = Left(partR, Instr(partR, delimiter)- 1)
	Else
		pos = Instr(1, qs, delimiter + argName + delimiter, 1)
		If pos > 0 Then
			getArgumentValue = "1"
		Else
			getArgumentValue = ""
		End If
	End If
End Function


EXAMPLE: Simple web agent: 

Sub Initialize
	Dim session As New NotesSession
	Dim docContext As NotesDocument
	Dim qs As String
	
	Set docContext = session.DocumentContext
	qs = docContext.Query_String_Decoded(0)
	
	Print "<pre>"
	Print "Product ID: " + getArgumentValue(qs, "ProdID")
	Print "Action: " + getArgumentValue(qs, "Action")
	Print "ShowStat: " + getArgumentValue(qs, "ShowStat")
	Print

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

"Send Notification: " + getArgumentValue(qs, "SendNotif") Print "</pre>" End Sub Agent called from browser with following URL http://localhost/tester.nsf/QSReader?openagent&ProdID=123456&Action=Remove&ShowStat returns these results: Product ID: 123456 Action: Remove ShowStat: 1 Send Notification:

This was first published in January 2001

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.