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

anubhavkapoor76
ServiceNow Employee
ServiceNow Employee

@NehaA3677346693  - I believe GlideURL works only on client side scripts. For me it worked on client script and not in the background scripts

 

See below:

 

https://developer.servicenow.com/dev.do#!/reference/api/xanadu/client/c_GlideURLV3API?navFilter=glid...

 

anubhavkapoor76_0-1729503813774.png

If you have access to this KB then view here: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783157

 

Please mark this correct or helpful if it works for you.

 

Cheers!!

Anu

any idea how we can do in background script?

Hi @NehaA3677346693 , 

On any form or screen, press ctrl + shift+ j. This will open java script executor. there you can paste your code and run it. Replace gs.info with alert to print anything. 

Mehta_0-1729504466407.png

 

The GlideURL API is client side and only can be use in client script, ui policy or client side code for UI Action.

It can be utilized in server side before not in background script.

 

Please mark this correct or helpful if it works for you.

@Mehta Thanks for your response. I am looking for a solution to run in background script as after fetching the values from url I need to perform some insert operations as well.