Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

gaidem
ServiceNow Employee

I've been needing to evaluate URI paramaters in areas of the application where the RP object hasn't been available. With a pointer from Tyler Jones I found a great script on stackoverflow.

Here is what you want to do:

Create a new script include named gup:
Script:



function gup( name, url_pass ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url_pass );
if( results == null ) return "";
else return results[1];}


Now you can access this doing something like this in a client script:


var x = GUP('parm name' window.location.href);


Or this in a server script:


var x = GUP('parm name', gs.getSession().getStack().top());

You will be returned with the value for that paramater.

1 Comment