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).

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)
		pos = Instr(1, qs, delimiter + argName + delimiter, 1)
		If pos > 0 Then
			getArgumentValue = "1"
			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 "Send Notification: " + getArgumentValue(qs, "SendNotif")
	Print "</pre>"
End Sub

Agent called from browser with following URL

returns these results:

Product ID: 123456
Action: Remove
ShowStat: 1
Send Notification:

This was first published in January 2001

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.