User criteria to restrict by country shown in user location

shembop
Tera Contributor

How would I format a script to restrict to a location's country value based on a users location record.

I am using Country to limit who can see certain things in the Service Catalog, and having trouble getting it to pull the right info.

8 REPLIES 8

Prasun
Giga Guru

use dot walking in the catalog entitlement script to restrict in servicenow. See the following link.



lets see the following script which shows a catalog for a user in South Africa



var userid = gs.getUserID();


var gr = new GlideRecord('sys_user');


gr.get(userid);


var fullLocation = gr.location.full_name;


if ( fullLocation.indexOf("South Africa") > -1 )


  {


  answer = true;


}


else


  {


  answer = false;


}



Legacy:Service Catalog Access Controls - ServiceNow Wiki


shembop
Tera Contributor

The new way in ServiceNow is to use User Criteria, and in this circumstance, I would use the advanced script. Would this change anything with your script approach?


Also, using the service Portal, would this scripting work?


I think the User Criteria functionality is available only on Knowledge Application


shembop
Tera Contributor

No, User Criteria is used for catalog items as well. We are using it today, but it makes no sense to add every location manually to the location filter when you can script out to use the country code. One of the other challenges with the script is you cannot use the glide record functionality on the Service Portal, you have to change your scripting to call a function in a script include.