How to use user criteria to select users based om specific company field?

Jacob64
Kilo Guru

Dear all,

At his moment we use groups to select users with specific company fields.
For example all users that are working for a company that is considered to be a customer  may use certain Catalog items.
Now we add these companies to a criteria group and all users working for a company that  have customer is true.
However. This changes all the time and it is likely that we miss out companies or allow companies that are no longer considered to be customers.  So beside changing the customer flag we also have to change the user criteria group by removing or adding the company.

What we would like to do is to add for example the customer field (or future new field content) to the user criteria and make the user criteria less difficult to maintain.

Can this be done by adding the specific field to the user criteria form and if so how do we do that?
Or do we need to add a script that gets the field value  and is so what wold be a proper script to do so?
Additional will such a way way of filter out the right users have an impact on performance?

Many thanks in advance!

Kind Regards,
Jacob

6 REPLIES 6

Niklas Peterson
Mega Sage
Mega Sage

Hi,

You can extend User Criteria if a corresponding field can be found on the user record. Otherwise you need to script the criteria.

 

https://docs.servicenow.com/bundle/vancouver-servicenow-platform/page/product/service-catalog-manage...

 

Regards,
Niklas

Hi Niklas,

Many thanks for your reaction.
I had to read the article a few time but I believe this might bring the solution.
I'm going to try this as soon as i'm in the offic e again and let you know if this is the solution!

Kind regards,
Jacob.

 

Wel unfortunately this does not really solve my problem.
It makes it easier to select the correct companies but still i need to maintain this every time the company record changes.
I would like to see that I can just grant access by checking a variable on the company record.
If I could use this and could add "all that have this value" then It would be perfect.
Perhaps I need a script for that?


Regards
jacob.

Hi,

Yes, then you need a script. Basically it needs to perform an evaluation and then return true if access should be granted or false if it should be denied. So if you have a custom field on the company table called u_customer you can check that for the logged in user with a user criteria script similar to this.

 

checkCustomerCompany();

function checkCustomerCompany(){

var userID = gs.getUserID(); //logged on user
var usr = new GlideRecord('sys_user');
usr.get(userID);

if (usr.company.u_customer == true) 
	{ 
		answer = true; 
	}  
	else { 
		answer = false; 
	} 
}

 

Regards,
Niklas