Home > Domino Tips > Developer > Quickly parse URL parameters
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Quickly parse URL parameters


Sean Haggerty
05.23.2004
Rating: -2.86- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

I got tired of cutting out the ParentUNID and Count and Start parameters from a URL when submitting a page from browsers. So I came up with this LotusScript function named "makeParams()" to make a list of parameters and their corresponding values, if any. The parameter can be accessed from the list in LotusScript by using the format paramlist("ParentUNID").

I've also provided this function in JavaScript below, too. (I tested it on Internet Explorer though, so I'm not sure how it'll work on Netscape, Opera, Mac, etc.) You can access the JavaScript list using paramlist["ParentUNID"].

LotusScript code:

Function makeParams()
'Better that paramlist is declared in 
(Declarations) by: Dim paramlist list as
String
'If you declare it here, the list dies when 
the function looses scope
 Dim paramlist list as String
 Dim arg As Variant
 Dim parts As Variant
 arg = Evaluate({ @explode
( Query_String ; "&") }, doc)
 Dim tempdoc As notesdocument
 Set tempdoc = 
s.currentdatabase.createdocument
 Forall params In arg
  tempdoc.params = params
  parts = Evaluate( {@explode
( params ; "=" )} , tempdoc)
  If Ubound( parts ) = 1 Then 
   paramlist(parts(0)) = parts(1)
  Else 
   paramlist(parts(0)) = ""
  End If  
 End Forall

' To test for a parameter use  IsElement 
( listName ( stringExpr ) )

If ( IsElement(paramlist("parametername") ) 
then
  'Then the string  <parametername> 
was in the URL

  'If it had a value associated with it then 
accessing the list 
  'with the string <parametername> 
will return the associated value
  'If you just included a parameter in the 
URL like  <&responses>
  'then just finding the string <&responses>
 is useful by itself.
  'For instance if 
Query_String=http://someDomain.com/
TheOnlyNotesDBwithoutScopeCreep.nsf/anyDBform
?OpenForm&ParentUNID=
3330E53C72B61DD588256E9D0025C853&responses
  'Calling <paramlist("ParentUNID")> 
returns the UniversalID 333...853
  'To check to see if responses is in the url 
IsElement tells you that
End If

End Function

JavaScript code:

locationHREF= 
"http://someDomain.com/TheOnlyNotes
DBwithoutScopeCreep.nsf/an
yDBform?OpenForm&ParentUNID=
3330E53C72B61DD588256E9D0025C853&responses";
paramlist = new Array();
contextlist = new Array();
splitReturn = locationHREF.split
(new RegExp("&","g"));
  for (paramNum in splitReturn) {
  parts = splitReturn[paramNum].split("=");
  if ( 2 == parts.length ) { 
   paramlist[parts[0]] = parts[1];
  } else {
   paramlist[parts[0]] = "";
  }
 }

// If you try to get the value of a 
Non-parameter it returns null
 if ( null==paramlist ["notaparameter"] ){
  alert("Not a param");
 }else{
  alert("Is a param");
 }

MEMBER FEEDBACK TO THIS TIP

Domino 6 has a command called @UrlQueryString that may be easier to use. Presumably it works with the LotusScript Evaluate command if you need to use it in LotusScript.

—Mark B.

******************************************

I think it's also worth pointing out that ND6 foregoes the need for any of this using the @URLQueryString function. Also, users can then use split and join in LotusScript rather than an Evaluate and @Explode.

I have found that I've had to rewrite code like these functions as they don't cater for characters such as quotation marks being passed in via the URL, and this effectively breaks the LotusScript as the @Explode can't cope. Of course, there are workarounds, but if you have ND6 you don't need to bother!

—Giles H.

******************************************

Re: LotusScript version

You can use the Split function for this. The code doesn't "URL decode" the parameters, so it will fail with values that contain spaces, "&" or other characters that can't appear or have special meaning in the URL.

Portions of the parameter value to the right of an "=" are lost -- e.g., "&Equation=e=m*c^2" would only see the value "e."

Andre Guirard

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Sean Haggerty. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Agent
Run or restart Notes/Domino agents via text messages
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
How to export data from a Lotus Notes database to a CSV file
Enable or disable scheduled agents without opening the Lotus Notes database design
Creating custom views in Lotus Notes databases
Editing fields in a Lotus Notes view with Ajax

JavaScript
Trap JavaScript runtime errors in Domino Web apps
JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
Write HTML and JavaScript in Notes view rows and columns on the Web
JavaScript detects Web browser type and version in Notes/Domino 8.0.2
JavaScript creates a jump box on a Lotus Notes Web form
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field
Converting Lotus Notes views to XML documents using JavaScript
Prevent errors on iFramed pages with JavaScript
How to add keyboard functionality for Lotus Notes documents

LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication
LotusScript filters and attaches files to a Notes form

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts