- 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 12:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:00 PM
I tried that and it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:25 PM
Odd that that's not working.
There are a few other things you can try:
var company = gs.getUser().getCompanyID()
OR
var company = gs.getUser().getRecord().getValue('company');
You can then evaluate the value of company like you are with manager.
It'd be easier to suggest solutions if you were more specific about what you've tried that hasn't worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:35 PM
Tried thisL
answer();
function answer(){
var company = gs.getUser().getCompanyID();
var manager = gs.getUser().getRecord().getValue('u_is_a_manager');
if((manager == true) && company == "enter sys id here"){
return true;
}else{
return false;
}
}
Tried adding it in the bucket list and selecting match all. Didn't work.
I also did a new GlideRecord but it didn't work either.