Nintex Forms – Reading Query String Values
There’s not much to say about this post. I had been asked about pulling our Query String values from a Nintex Form.
It’s actually not that hard. The following is a little code that you can put into the Custom Javascript section of the form settings.
NWF$(document).ready(function()
{
var myVars = getQueryStringsIntoHashtable();
if(typeof myVars['name'] === 'undefined' || myVars['name'] == null)
{
// do something if the query string value is not found
}
else
alert(myVars['name']);
});
function getQueryStringsIntoHashtable()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
In the above example, I’m looking for a name,value pair where the name equals “name”. If it finds it, it pops up an alert box with the value.
The getQueryStringsIntoHashtable function reads all the parameters from a Query String, splits them up and builds a hashtable (name,value pair).
So if you have a url like http://mycompany.com?x=1&y=2&name=LasVegas, you’ll end up with a hashtable that looks like this :
x = 1
y = 2
name = LasVegas.
To access the values, you use the names. In my case, the function call result was stored in a variable (myVars). To access the “name” value, you simply do :
myVars[‘name’];