How to Fetch sys_id from url and set value on refrenece field on ServiceNow.

Prithvirajk
Tera Contributor

I Want to fetch the the sys_id from below URL and Set that value in Employee_id Field Which is reference Field what are the best possible ways to do that?

I want to make this use case dynamic. The sys_id is of emplyee name.

URL= https://dev309459.service-now.com/sp?id=sc_cat_item&sys_id=0962deffc38a2610b0de7f65e40131f5

 

 

Prithvirajk_0-1750912844091.png

 

1 ACCEPTED SOLUTION

Nilesh Pol
Tera Guru

@Prithvirajk 

You can verify sys_id from link using URL class, 

verify with the below code in client callable script include:

 

var url = new URL(window.location.href);
var sysId = url.searchParams.get('sys_id');

if (sysId) {
   return sysId;
}

and use GlideAjax in your on load client to set sysId for employee_id with in Onload client script,

View solution in original post

4 REPLIES 4

J Siva
Tera Sage

Hi @Prithvirajk 
Are you trying to set the employee name using the information of the currently logged-in user? I believe the sys_id in the URL mentioned above is linked to the catalog item, not the user table.
Please share more information on your requirement.
Regards,
Siva

Ankur Bawiskar
Tera Patron
Tera Patron

@Prithvirajk 

you are not including any user sysId in URL.

Then how can you get it and set in Variable?

If you are redirecting to this catalog item from some UI action etc then it makes sense to include user sysId in URL parameter and then you can use onLoad catalog client script and get the sysId and set it

For that check this

3 Ways to Populate Values in ServiceNow via the URL 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Prithvirajk 

Thank you for marking my response as helpful.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

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

Nilesh Pol
Tera Guru

@Prithvirajk 

You can verify sys_id from link using URL class, 

verify with the below code in client callable script include:

 

var url = new URL(window.location.href);
var sysId = url.searchParams.get('sys_id');

if (sysId) {
   return sysId;
}

and use GlideAjax in your on load client to set sysId for employee_id with in Onload client script,