Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

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