Manage Learn to apply best practices and optimize your operations.

Parsing URL Parameters with Ease

URL Parameter is an important mode of data posting from the Web. When I started to work a lot on Web based applications using Domino, I started to realize that handling URL Parameters in LotusScript is much more painful than in formula.

Hence, I came up with this general purpose function that parses URL parameters. I place this function (along with many other general purpose functions) in a Script Library called Environment and use the library in all my scripts.

URL Parameter Syntax:
The code assumes the following URL Parameter Syntax.
URL&Key1=Value1&Key2=Value2&...

Example:
<A HREF="http://abcd.com/xyz/mnz.nsf/SomeElement?Open&Op=Load&Report=My+Special+Report">http://abcd.com/xyz/mnz.nsf/SomeElement?Open&Op=Load&Report=My+Special+Report</A>

In this case, the URL has 2 parameters 'Op' and 'Report' (I call the name of the parameter as a Key). The Value follows the equal (=) sign. Please note that the Value of the Report Key has spaces, and the spaces are replaced by a plus(+) sign. This is a de facto standard on the Web.

THE Code:
The function, parseURLParameters uses a support function called plusToSpace that converts "+" in a string to space. The function is given below the parseURLParameters function.

Sub parseURLParameters(URLParameters As String, Parameter List As String)

Dim DelimiterPos As Integer
Dim CurrentParameter As String
Dim SeperatorPos As Integer
Dim Key As String
Dim Value As String
Dim LeftToParse As String

LeftToParse = URLParameters

Do
DelimiterPos = Instr(LeftToParse, "&")

If DelimiterPos = 0 Then
CurrentParameter = LeftToParse
LeftToParse = ""
Else
CurrentParameter = Left(LeftToParse, DelimiterPos-1)
LeftToParse = Right(LeftToParse, Len(LeftToParse) - DelimiterPos)
End If

SeperatorPos = Instr(CurrentParameter, "=")
If SeperatorPos > 0 Then
Key = Left(CurrentParameter, SeperatorPos-1)
Value = Right(CurrentParameter, Len(CurrentParameter) - SeperatorPos)
If Trim(Key) <> "" Then Parameter(plusToSpace(Key)) =
Trim(plusToSpace(Value))
End If
Loop While DelimiterPos > 0

End Sub

Public Function plusToSpace(query_string As String) As String

Dim strlen As Integer
Dim i As Integer

strlen = Len(query_string)
For i = 1 To strlen
If (Mid(query_string, i, 1) = "+") Then
Mid(query_string, i, 1) = " "'
End If
Next
PlusToSpace = query_string
End Function

Usage:
Call this function as follows,

Dim Session As New NotesSession
Dim Doc As NotesDocument
Set Doc = Session.DocumentContext

Dim Parameter List As String
Call parseURLParameters(Doc.Query_String(0), Parameter)

You can then use Parameter as follows,

RequestedReport = Parameter("Report")

Needless to state, that "Report" is the name of the key. When employed for the above example, Parameter("Report") will return "My Special Report"

Parameter("Key") will return an error if the Key is not present in URL Parameter. You can confirm if "Key" is present in the URL Parameter by using IsElement function.

IsElement(Parameter("Key")) will be true, if the Key is defined in the URL Parameter.

Good luck and hope you enjoy using the function as much as I did coding this. Do send your questions/feedback to rrajah@icsfoodone.com


Dig Deeper on Domino Resources - Part 7

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close