How to get current URL link in a variable.

Ilavarasu2
Tera Contributor

How to get current URL link in an variable? 

Requirement is from incident form through UI action url redirected to record producer which has to create change record.

Once change record created, Incident form has to be get updated with caused_by related reference field to change record.

Can you please help to get the URL link in an varaible that redirects to record producer.

 

Thank you

1 ACCEPTED SOLUTION

Hi,

you need to write onLoad catalog client script to get the url parameter value

Is the extra parameter in url with name as sys_id ?

if yes then try this

function onLoad(){

var url = top.location.href;
var value = new URLSearchParams(url).get("sys_id"); // give here the parameter name
g_form.setValue('hidden_variable', value);

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

AnandKumar1
Tera Expert

Hi Ilavarasu,

can you please clarify the below points.

1) is your requirement is to create a change record from incident form.

2)post change creation, do you want to update a field in incident form.

3) Why you have to redirect to record producer.

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will have to pass the incident sys_id from the UI action to the record producer form.

Store that in the hidden variable using onLoad client script

In the record producer script you can use this script

var inc = new GlideRecord('incident');

inc.get(producer.incVariable);

inc.caused_by = current.sys_id;

inc.update();

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank you Ankur. 

I have passed the incident sys_id in redirect URL(UI Action). Now I got struck in getting the current URL in a variable for getting the incident sys_id to update in the invisible variable. can I have the function that can get current URL in a variable. find_real_file.png

 

 Thank you

Hi,

you need to write onLoad catalog client script to get the url parameter value

Is the extra parameter in url with name as sys_id ?

if yes then try this

function onLoad(){

var url = top.location.href;
var value = new URLSearchParams(url).get("sys_id"); // give here the parameter name
g_form.setValue('hidden_variable', value);

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader