The CreatorCon Call for Content is officially open! Get started here.

Advanced User Criteria for Catalog Item - "specific company managers only"

damzelev
Tera Contributor

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!

1 ACCEPTED SOLUTION

Yifeng Zhang
Mega Expert

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;}

 

 

View solution in original post

11 REPLIES 11

sachin_namjoshi
Kilo Patron
Kilo Patron

You don't need to write code for checking company.

You can use below in your user criteria and use match all in your user criteria

 

find_real_file.png

 

Regards,

Sachin

I tried that and it is not working.

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.

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.