If script to fetch Employee's country in ServiceNow workflow

Ankita Gupte
Kilo Sage

We have "employee_name" variable on catalog item, I have a requirement if the user selected in employee name has location.country as India then return value as yes in if script orelse no.

 

I have written below script but its not working, please advice on the same.

 


var employeeName = current.variables.employee_name;

var response = 'no';

// Query the User table to get the user's details
var userGR = new GlideRecord('sys_user');
if (userGR.get('user_name', employeeName)) {

// Check if the user's location is set and if the country is India
var locationGR = new GlideRecord('cmn_location');
if (userGR.location && locationGR.get(userGR.location)) {
if (locationGR.country == 'India') {
response = 'yes';
}

// Return the response
response;

 

10 REPLIES 10

var emp = current.variables.employee_name;
var response = "";
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('location.country=USA^ORlocation.country=india^sys_id='+emp);// replace USA with another location
gr.query();
if(gr.hasNext())
{
response = 'Yes';
gs.info('yes'); -->
return response;
}
else{
response = 'No';
gs.info('no');
return response;
}