Create Advanced Script on User Criteria for locations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 08:49 PM
Hello,
I am trying to create an Advanced Script for User Criteria to make a content item available for certain locations. There are about 100 locations that the content item should be available for. Below is the script that I am using and is not working.
checkCondition();
function checkCondition() {
var queryString = 'city=Sacramento^ORcity=Wichita';
var gr = new GlideRecord('cmn_location');
gr.addEncodedQuery(queryString);
gr.query();
if (gr.hasrNext()) {
answer = true;
}
return false;
}
Any idea on what I am doing wrong?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:23 PM
The location information on sys_user is (empty), and therefore this script is not working. In User Criteria, there is a location field that we can use to set on the Available For. My question is why would the script not work when checking for those locations?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:36 PM
First of all the user location cannot be empty, How does system know what is his location? You need to populate locations on user table if the user critieria should validate the access.
Secondly you wont need the advanced script for validating locations. There is a Location list field on the user criteria which can be updated with all required locations for which your catalog item requires access.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:50 PM
I am sorry, but I am new to ServiceNow, so still learning the basics.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:17 PM
Hi,
I believe this is what is required.
If logged in user has location city as either Sacramento or Wichita then show the catalog
if yes the update script as below
answer = checkCondition();
function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
var city = user.location.city;
if(city == 'Sacramento' || city == 'Wichita')
return true;
else
return false;
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:24 PM
I just tested out the script and it did not work. The location records on sys_user is (empty). Are there any other work arounds?