Pull the 'Request for' location into a catalog variable

KristinaB
Giga Contributor

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
    RequestFor.png
  • 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.

1 ACCEPTED SOLUTION

manikorada
ServiceNow Employee
ServiceNow Employee

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()


View solution in original post

11 REPLIES 11

Mike Allen
Mega Sage

Maybe javascript:current.variables.request_for.getRecord().getValue('location')?


Thanks Mike. Unfortunately this didn't work. The variable 'location' is not pulling anything. That's the issue I'm running into


Maybe javascript:current.variables.request_for.location ? As this is a reference to the user table it should work.


Probably going to have to do an AJAX call to pull the information back.   The gs.getUser() is in the session, so it is easily accessible.   This is a client interaction with a server lookup, so I think AJAX is the way to go.