logo

Using Query_String parameters

Using the Query String portion of a URL is a useful method to pass information to a new document. For example when creating a new repsonse document:

..db.nsf/response?OpenForm&ParentUNID=766a4d...

Getting this value would be relatively easy. However, if the Query String consisted of multiple sets of arguments it gets a little more complicated. This method makes it simple to find a value in your form, using Formula language.

First thing to do is to create two Computed For Display, Multi-Value, Text fields with New Line to separate and display entries. I usually put these in to a Common Fields subform so that they are available in every form I use, just in case. This is also a good place to put the "Query_String" and "Query_String_Decoded" fields. Make these Computed For Display with a value the same as their name. These fields MUST appear on the form somewhere in order for Domino to be able to reference them.

The first field is called "ArgNames" and its formula is:

@Left(@Explode(@Right(Query_String_Decoded;"&");"&");"=")


The second field is called "ArgValues" and its formula is:

@Right(@Explode(@Right(Query_String_Decoded;"&");"&");"=")


Note: We have used Query_String_Decoded here and not, the more well known, Query_String CGI variable. I won't patronise you by explaining the difference...

Now that we have our lists of parameters we can use them throughout our forms. Let's say we have a field called "FirstName", whose default value we want to get from a parameter called "fName" in the URL. Place the following in to the Default Value event of the field:

@Replace("fName";ArgNames:"fName";ArgValues:"")


If the "fname" parameter is in the "Query_String" portion of the URL then its corresponding value is extracted from the "ArgValues" field. If not then a blank "" will be added.

We could use this in lots of other places as well, such as the Window Title or in Computed Text areas. Also, making the Computed For Display fields hidden would then make them available to JavaScript in the browser.


Note: In R5 there is a new "un-documented" @Formula called @GetMembers.

@GetMembers( sourceList; start; count)

sourceList = List from which you want to obtain value
start = position in list to start getting items (number)
count = number of items to return (number)

So, in the above example the code would then be simplified to:

REM "Check that the parameter exists";
pos:=@Member("fname";ArgNames);
@If(pos>0; @GetMembers(ArgValues; pos; 1); "")

Feedback

  1. This is too easy

    This solution is too easy. Why is it that all of the solutions offered on Notes.net don't come close to this one for simplicity? 'Cos you're the best!

    I was thinking of using the query_string to reformat a page for printing (ie. by getting a different page layout document). However, I notice that you have handled this in a different way. Could you share a few tips on how you did this?

  2. Your method doesn't work when you have a & in a va

    Just try for example:

    Openform&SelectedCompany=Siemens%20Business%20Services%20GmbH%20&%20Co.%20OHG%20 (SBS)&Nr=HWAL-57LD54&Type=Contact

    The value of the selectedcompany argument is: Siemens Business Services GmbH & Co. OHG (SBS)

    But your function returns: Siemens Business Services GmbH

    1. Re: Your method doesn't work when you have a & in a va

      I had noticed the same thing myself and have a work around. I ran into the same problem when dealing with company names, like law offices: Sue'em, Bone'em & Hose'em

      The problem is with the Query_String_Decoded. I don't think it's a true CGI variable, but one of those things Domino provides. I may be wrong about that. I assumed since it's buggy that it's a Lotus implementation.

      I still like Jake's technique, however, and use it extensively. It's just real handy to have all your arguments and variables in a list, all the time.

      My work around is to decode the Query_String CGI variable instead. This means you have to do all of the decoding your self.

      I do something like this:

      For the Arguments: encoded:=@Left(@Explode(@Right(Query_String;"&");"&");"="); fixed := @ReplaceSubstring(@ReplaceSubstring(encoded;" ":"%20":"%26":"%23":"%24";"+":" ":"&":"#":"$");"%25":"+";"%":" "); fixed

      The Values: encoded:=@Right(@Explode(@Right(Query_String;"&");"&");"="); fixed := @ReplaceSubstring(@ReplaceSubstring(encoded;" ":"%20":"%26":"%23":"%24";"+":" ":"&":"#":"$");"%25":"+";"%":" "); fixed

      when I need to pass something in a query_string, I encode it myself. For example: key := Vendor_Name; encoded:=@ReplaceSubstring(@ReplaceSubstring(key;"%";"%25");" ":"&":"#":"$";"%20":"%26":"%23":"%24") "[/" + dbPath + "/" + VendorForm + "?OpenForm&VENDORNAME=" + encoded + "]"

  3. Has anyone tried @GetMembers with R6

    or know the first version of R5 that supports this function? I'd like to use it but want to make sure they didn't dump it in R6.

    Thanks!

      • avatar
      • Stan Rogers
      • Mon 23 Sep 2002

      Re: Has anyone tried @GetMembers with R6

      No need in R6 -- lists have subscripts, and you have access to looping in Formulas. In the old days, the "accepted" way of getting the fourth member of a list was @Subset(@Subset(list;4);-1). In D6, it's simply list[4], or (to make it more germaine to the point here), getting a last name would be argvalues[@Member(argnames;"LastName")].

    1. Re: Has anyone tried @GetMembers with R6

      In R6, you can just use the @URLQueryString function to get the value directly.

      • avatar
      • harkpabst_meliantrop
      • Thu 6 Feb 2003

      Re: Has anyone tried @GetMembers with R6

      Funny, how Stan and Chris missed the point completely. :-) However, as R6 is out now for a while, everyone will have noticed that @GetMembers is still functional (if still unsupported).

      Show the rest of this thread

  4. Catch Querystring in an iFrame

    Maybe i'm just plain stupid, but i'm trying to get some querystrings in an iFrame. I'm using iFrames in my form to display multiple views. when i retrieve the querystring on the mainform, i get it just fine. When i use the same code on a iFrame, i get an empty string?!

    why can't i get this value in an iframe?

    1. Re: Catch Querystring in an iFrame

      I have faced the same problem if anyone knows its solution then share with others

  5. Qeury_String_Decoded losing varaibles at the end

    I'm having a weird problem with saving the variables. Using the following query string I get everything displayed perfectly in a form but it saves only the 'name@domain.com' bit and does not save the 'Product Enquiries' bit! "?OpenForm&To=name@domain.com&Cat=Product%20Enquiries"

    Looking at the field values of the save document, the Query_String field only has "http://url?OpenForm&To=name@domain.com&Seq=1", it has dropped the "&Cat=Product%20Enquiries" !

    Any suggestions?

    1. Re: Qeury_String_Decoded losing varaibles at the e

      Sorry, the Query_String field holds : "OpenForm&To=name@domain.com&Seq=1"

    2. Re: Qeury_String_Decoded losing varaibles at the end

      You probably need to escape the @ in the address to its encoded equivalent of %26.

      You can use escape() in javascript or @URLEncode() in Formula language.

      Jake

    3. Re: Qeury_String_Decoded losing varaibles at the end

      Here could you try with the same urlopen with splitted to quotes as:

      Given:

      "?OpenForm&To=name@domain.com&Cat=Product%20Enquiries"

      Suggesstion:

      FIELD HTTP_Host := HTTP_Host; FIELD dbname := dbname; url := "http://"+HTTP_Host+"/"+dbname+"/formname??OpenForm&To="+"name@domain.com"+"&Cat ="+"Product%20Enquiries"; @URLOpen(url)

  6. my idea

    get you want by functin from "Query_String_Decoded" :

    Function GetParameter(Byval paramName As String, Byval queryString As String) As String ' Given a QUERY_STRING, this function returns the value of the specified parameter. For example, ' GetParameter("size", "color=red&size=10&qty=4") returns "10". Dim startPos As Integer , endPos As Integer , skipLen As Integer queryString = "&" + queryString + "&" + paramName + "=" + "&" paramName = Ucase("&" + paramName + "=") skipLen = Len(paramName) startPos = Instr(Ucase(queryString), paramName) + skipLen endPos = Instr(startPos, queryString, "&") GetParameter = Mid(queryString, startPos, endPos-startPos) End Function

  7. Query_String_Decoded only works in my DEV copy

    I have a strange one: In my DEV environment, the Q_S_D works beautifully, but when I promote it to the Web, my values are not saved on the submit. All other values in the form save perfectly, but I just get “OpenForm&Seq=1” and of course my fields that contained the argument values are blank.

    Help?!?

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Forms"

« Previous Article Next Article »
Effective use of the FileCloseWindow Command   Limit amount of input in a field

About This Article

Author: Jake Howlett
Category: Forms
Hat Tip: Jim Fricker; Paul Pentony
Keywords: URL; Query String; Decoded;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »