- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2015 12:38 PM
Hi all,
I'm trying to populate a variable on a catalog item based on the Request For widget on a catalog item.
I currently have a script that pulls the location of the person logged into ServiceNow into a variable but that may be a service desk person and the request may be for a person in a different location. I want it to pull the location of this person.
- I've added the Request For widget to the catalog home page
- I have a variable set called location and it pulls the location of the person submitting the request (the person logged into ServiceNow). The default value for this variable set is javascript: gs.getUser().getRecord().getValue('location')
Any ideas on how to update this script to pull the location of the person listed in the request for rather than the person who is logged in? Thanks so much.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2015 01:35 PM
Kristina,
You need to create a script include like this:
Name : getLocation
Script:
function getLocation()
{
var cart = new GlideRecord('sc_cart');
cart.addQuery('user',gs.getUserID());
cart.query();
if(cart.next())
{
return cart.requested_for.location;
}
return '';
}
Now, have the default value as javascript:getLocation()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2015 10:33 AM
Thank you so much everyone! This one appeared to work almost perfectly for us!
We had to update the return cart.requested_for.location to add.getDisplayValue();
When we added logging, it appears to run every time you look at a RITM. Would it affect performance?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2015 10:28 PM
Hi Kristina,
You need to proceed as Mike Allen suggested .Just make sure that onChange() script is on field Requestor (caller_id) and you are passing the same field(Requestor) as a Ajax parameter. If you are passing the logged in user in Ajax parameters then it won't work.
Thanks!
Gurpreet