Search
Contribute
Navigation
- 8.5
- 8.5
- action bar
- agents
- ajax
- app dev
- application
- Beginner
- Best Practices
- bidi
- Browser
- Build
- Caching
- capitalization
- CGI variables
- Checkbox Group
- Classic Web Server
- Classic Web Server
- client
- code snippets
- command buttons
- components
- composite applications
- Container Controls
- context
- context menu
- controls
- converters
- Cookie
- createForm
- css
- custom
- Data binding
- Data Palette
- Data Table
- database
- datetime
- DAV
- db2
- debugging
- design elements
- Designer
- developing
- dialog boxes
- Display Error Control
- Display Errors Control
- Dojo
- Dojo
- Domino
- Domino Designer
- Domino Designer 8.5
- DXL
- Eclipse
- ECMAScript
- ellipses
- error handling
- errors
- events
- Expeditor
- ExternalContext
- FacesContext
- FAQ
- fields design
- forms
- formulas
- getting started
- globalization
- glow
- handler
- hover help
- HTML
- http
- hybrid
- icons
- input validation
- interaction
- interface
- internationalization
- ISV XPages View Icon
- Java
- JavaScript
- JSF
- JSON
- Key bindings
- layout
- left-to-right
- letterhead
- lighting
- localization
- logging
- Lotus Script
- Lotus Script Query_String
- Lotusphere 2009
- LotusScript
- ltr
- mask
- memory
- menu bar
- messages
- mnemonics
- navigation
- navigator
- new user
- Notes 8
- NotesXspDocument
- notes.ini
- ntf
- numbers
- open button
- Open Source
- OpenNTF
- outline
- panels
- Partial Update
- pattern matching
- performance
- Portal
- preferences
- programming
- punctuation
- queryview
- Radio Button Group
- radio buttons
- Redbooks wiki
- regex
- regular expressions
- repeat control
- Repeats
- replica
- rich client
- Rich Text
- right-to-left
- roadmap
- Robot
- Rohit
- RSS
- rtl
- Sametime
- sample code
- Scope
- search
- security
- server
- shadow
- Shortcuts
- SHOW106
- simple actions
- size
- skipContainers
- SOA
- soft deletions
- states
- stationary
- status bar
- subforms
- tabs
- templates
- test
- title bars
- titles
- toolbar
- tooltips
- troubleshooting
- validation
- Variables
- Video
- View
- View Control
- ViewPanel
- views
- Web
- Web Server
- Web services
- working set
- XHTML
- XML
- xpage
- XPages
- XPages
- XSPClientDojo
- $$ViewTemplate
- @Formulas
Go elsewhere
Query String Parser
![]() |
LotusScript
, Programming
, Web applications
Lotus Script Query_String |
Ernest Leyva 11/06/2008 |
Ernest Leyva 11/06/2008 |
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.
There is a potential flaw in your routine. It doesn't fetch the entire value if there are = inside a parameter-value.
E.g. { Link }
Safer way:
'Split the querystring on "&" -> parameters
Forall parameter in parameters
name = Strtoken( parameter, "=", 1 )
params( name ) = Replace( parameter, name+"=", "" )
End Forall
Hi
Thanks for the comment. This is the fixed version of the code. It also changed the parameters to make it slightly easier to invoke:
Function parseQS( session as NotesSession, params List As String ) As Integer
Dim buffer As Variant, pair As Variant, ceiling As Integer, i As Integer
On Error Resume Next
Erase params
buffer = Split( session.DocumentContext.Query_String(0) , "&" )
ceiling = Ubound( buffer )
For i=0 To ceiling
pair= buffer(i)
params( Lcase( strToken( pair, "=", 1, 5 ) ) ) = strToken( pair, "=", 2, 5 )
Next
parseQS = ceiling
End Function



