Parse keys and values from a URL with @Formula

Normally, when you want to get a value from a list, depending on another list, you can use @Member, like this:

fieldList:="FirstName" : "LastName" : "FullName"; valueList:="Johan" : "Känngård" : "Johan Känngård"; @SubSet(@SubSet(valueList; @Member("FullName"; fieldList)); -1)

The example above returns ”Johan Känngård”, as it has the same index in the lists as ”FullName”. If you want all matching values from the value list, you have to do like this:

fieldList:="FirstName" : "LastName" : "FullName" : "FirstName" : "LastName" : "FullName"; valueList:="Johan" : "Känngård" : "Johan Känngård" : "Bill" : "Gates" : "Bill Gates"; valuesToGet:="FullName"; @Trim(@Right(fieldList + "-" + valueList; valuesToGet + "-"));

The example returns the list ”Johan Känngård” : ”Bill Gates”. It’s perfekt when handling URL:s, since they might contain multiple keys with the same name, like: ”http://server.com/db.nsf/myForm?OpenForm&Firstname=Johan&LastName=Känngård&FullName=Johan Känngård&FirstName=Bill&LastName=Gates&FullName=Bill Gates”. To parse it, I use two lists, one with the keys and one with the values, replacing encoded ampersands, like this:

queryString:="OpenForm&Firstname=Johan&LastName=Känngård&FullName=Johan Känngård" + "&FirstName=Bill&LastName=Gates&FullName=Bill Gates"; keys:=@ReplaceSubstring(@Left(@Explode (@Right(queryString; "&"); "&");"="); "!@amp@!"; "&"); values:=@ReplaceSubstring(@RightBack(@Explode (@Right(queryString; "&"); "&");"="); "!@amp@!"; "&");

Normally, the queryString variable is not needed, since I use the Query_String_Decoded field. To get the values of a specific key, use:

key:="FullName"; queryString:="OpenForm&Firstname=Johan&LastName=Känngård&FullName=Johan Känngård" + "&FirstName=Bill&LastName=Gates&FullName=Bill Gates"; keys:=@ReplaceSubstring(@Left(@Explode (@Right(queryString; "&"); "&");"="); "!@amp@!"; "&"); values:=@ReplaceSubstring(@RightBack(@Explode (@Right(queryString; "&"); "&");"="); "!@amp@!"; "&"); @Trim(@Right(keys + "~" + values; key + "~"))

Since I use URL parsing a lot in forms, I have two shared fields (URLKeys and URLValues) that makes the job of getting the URL argument keys and values.