User Criteria Advance Problem with Catalog Item

Tomas Linde
Tera Expert

 

Hello everyone,
It is the first time that I use User Criteria and I try to make the catalog item viable only for itil users that do not contain the keyword "Manager" in their firstname and/or lastname. I have tried this advance User Criteria without success, any ideas.
All the best

 

function evaluateControl() {

  var user = new GlideRecord('sys_user');
  user.query('sys_id=' + user_id);
  user.next();

  var firstName = user.getValue('first_name').toLowerCase();
  var lastName = user.getValue('last_name').toLowerCase();

  var roles = new GlideRecord('sys_user_role').query('user=' + user_id);
  roles.next();

  var isITIL = roles.getValue('role') === 'itil';
  var containsManager = firstName.includes('manager') || lastName.includes('manager');

  if (isITIL && !containsManager) {
	return true;
  } 
  return false;
}

 

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi @Tomas Linde , 

I see your all 3 posts with similar query, any reason the user has "manager" keywords in the first and last name, are they actual users or some kind of custom service accounts and you are trying to restrict those user on catalog item. 

If that is the case, those user should have some other parameter like user type which can be use in User Criteria.

 

-Thanks,

AshishKM

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi @AshishKM 

They are default users to whom I want to limit access, which contain the role itil and that keyword in common as parameters to limit access

you can disable those default user via active=false instead of applying the user criteria at variable level.

or you can apply the condition on that catalog item variable.


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Thanks for your response @AshishKM , but I don't want to disable users, I just want to use a correct User Criteria to limit access to the catalog item and know if the one I am applying is correct.