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:04 PM
Hi mkader,
Could you try this script:
checkCondition();
function checkCondition() {
var queryString = 'city=Sacramento^ORcity=Wichita';
var gr = new GlideRecord('cmn_location');
gr.addEncodedQuery(queryString);
gr.query();
if (gr.next()) {
answer = true;
}
return false;
}
Please mark it correct if this helps you.
Regards,
Aniket Sawant.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2020 09:06 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2020 09:06 PM
Hi,
You are directly querying on the location table instead of comparing it with the location of current user. Unless you do this, it wont validate the user access. So Ideally you will need to fetch the user location name and check whether it is Sacramento or Wichita.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2020 09:10 PM
eg script
answer = false;
var location = '';
var user = new GlideRecord('sys_user');
if(user.get(gs.getUserID()){
location = user.location.name;
if(location == 'Sacramento'){
anwer = true;
}
}