- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 12:53 PM
Hi all,
I'm trying to create a User Criteria script for a catalog item that checks if the user is a manager and if he belongs to a particular company.
I have the following code working for the manager requirement (we have a custom field [u_is_a_manager] true/false)
answer();
function answer(){
var manager = gs.getUser().getRecord().getValue('u_is_a_manager');
if (manager == true)
{return true;}
else
{return false;}
}
I'm having trouble adding the company requirement to this script. I've tried many different ways but it keeps being available to all company managers when I impersonate...
Appreciate any help!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:34 PM
The reason Sachin's answer didn't work is because when you have a script as well as other condition (in this case, the company) is that the script condition will override other conditions.
so in other words, if your script field is not empty, it's now considered as "advanced" user criteria and will only evaluate the script and ingores other condition.
SO the solution is, put all your conditions in a script.
In this case, IN ADDTION TO your existing code, you could add:
var manager = gs.getUser().getRecord().getValue('u_is_a_manager');
var manID =gs.getUser().getRecord().getValue('sys_id');
if (manager == true)
{
var CompanyGr = new GlideRecord ("The_table_that_associates_manager_to_company");
CompanyGr.addQuery("u_manager", manID);
CompanyGr.addQuery("u_Company", "TheCompanyName"); // what ever your query condition should be..
CompanyGr.query();
If(CompanyGr.next())
{
return true;
}else{
return false;
}
}
else
{return false;}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:42 PM
Admin will override user criteria I think...
Also maybe try to log the output and check the answer is actualy correct by your logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:46 PM
Tried this as well"
answer();
function answer(){
var company = gs.getUser().getRecord().getValue('company);
manager = gs.getUser().getRecord().getValue('u_is_a_manager');
if((manager == true) && company == "enter sys id here"){
return true;
}else{
return false;
}
}
answer();
function answer(){
var company = gs.getUser().getRecord().getValue('company);
manager = gs.getUser().getRecord().getDisplayValue('u_is_a_manager');
if((manager == true) && company == "enter name here"){
return true;
}else{
return false;
}
}
Neither worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:34 PM
The reason Sachin's answer didn't work is because when you have a script as well as other condition (in this case, the company) is that the script condition will override other conditions.
so in other words, if your script field is not empty, it's now considered as "advanced" user criteria and will only evaluate the script and ingores other condition.
SO the solution is, put all your conditions in a script.
In this case, IN ADDTION TO your existing code, you could add:
var manager = gs.getUser().getRecord().getValue('u_is_a_manager');
var manID =gs.getUser().getRecord().getValue('sys_id');
if (manager == true)
{
var CompanyGr = new GlideRecord ("The_table_that_associates_manager_to_company");
CompanyGr.addQuery("u_manager", manID);
CompanyGr.addQuery("u_Company", "TheCompanyName"); // what ever your query condition should be..
CompanyGr.query();
If(CompanyGr.next())
{
return true;
}else{
return false;
}
}
else
{return false;}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:45 PM
The_table_that_associates_manager_to_company - I don't have a custom table that does this. Could I use the core_company?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 02:24 PM
Yeah you should be able to, you can query any OOB table just like a custom table
you just need to query the place where it stores information of which company does this manager belong to.