The CreatorCon Call for Content is officially open! Get started here.

Fetch URL param values from a string

NehaA3677346693
ServiceNow Employee
ServiceNow Employee
I have a urlstring as below. I want to fetch sysparm_query value from below in background script but I am facing issue.
 
 
I have tried below but didn't work-

 

1.

var url = new GlideURL(urlString);

var value = new URLSearchParams(url).get('sysparm_query');

gs.info(value);

 

2.

var parmVal = url.getParameter('sysparm_query');

6 REPLIES 6

gs.action.getGlideURI().getMap().get('URL Parameter Name') is the api that you can use. Try this in any business rules so this can on run can pick up values from your url as while using background script your url does not have any parameter to fetch so it will not be able to do the action on background script.

Saurabh _
Tera Guru

Hi @NehaA3677346693 

       This below code you can run to fetch sysparm_query form url.

var url = "https://buildtoolsdev5.service-now.com/rm_story_list.do?sysparm_query=epic.numberINEPIC1099615%2CEPIC1099607%2CEPIC1099483%2CEPIC1096537%2CEPIC1096534%2CEPIC1093768%2CEPIC1093766%2CEPIC1093765%2CEPIC1093764%2CEPIC1093763%2CEPIC1093762%2CEPIC1093760%2CEPIC1093757%2CEPIC1083737%2CEPIC1087211%2CEPIC1102546%5Etype%3DDevelopment%5Estate!%3D4&sysparm_view="

pos_1 = url.indexOf("sysparm_query=");
gs.info(pos_1);
pos_2 = url.indexOf('sysparm_view');
gs.info(pos_2);

var sysparm_query = url.substring(pos_1 + 14, pos_2);
gs.info(sysparm_query);

 

Thanks.. 🙂