- 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 02:32 PM
I just did quick check on the OOB core_company table and it does not seem to describe manager-company association.
Then I read again in your question, so you are not actually looking for a manager of the company, but
you are just looking for a person who is BOTH A manager, and belongs to A company,
so in your query you just have to query the sys_user table,
like this :
UserGr = new GlideRecord(sys_user);
UserGr.addQuery("company", sys_id_of_the_company_record_in_core_company);
But to be fair, that u_is_a_manager seems like a custom field on the sys_user table, which isn't really a good practice(IMO), because it just tells you this user is A manager, but a manager of what ? it doesn't say, how would you differentiate if a Person is a manger of company A and company C but not a manager of company B..... then this field is overloaded and not useful, that's why I assumed you would have an association table.
UserGr.query();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 01:53 PM
For true/false field getRecord() with getValue() returns either 0 or 1
Below script check if the logged in user is a Manager and also belongs to a specific company
Try this script
var comp = gs.getUser().getCompanyID();
if(gs.getUser().getRecord().getValue('u_is_a_manager')=='1' && (comp == 'COMPANY_SYS_ID')){
answer = true;
}
else
answer = false;