User Criteria Catalog Item

Tomas Linde
Tera Expert

Hello everyone,
I have created this User Criteria to prevent access to all users who contain the keyword "Manager" in their first and/or last name, it works for me but I also need it to prevent me from selecting this type of user in a variable of type reference to the "sys_user" table of my catalog item, any ideas (it's my first time using User Criteria).
Greetings and thank you.

 

function evaluateControl() {

  var user = new GlideRecord('sys_user');
  user.get(gs.getUserID());

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

  firstName = firstName.toLowerCase();
  lastName = lastName.toLowerCase();

  var containsManager = firstName.indexOf('manager') !== -1 || lastName.indexOf('manager') !== -1;

  if (containsManager) {
    return false;
  }

  return true;
}
5 REPLIES 5

jMarshal
Mega Sage
Mega Sage

Simply set the reference qualifier field (reference_qual_condition) on the reference field in question with "Name | Does Not Contain | manager"!

See an example below, where I did this for the "caller" field on an incident record.

jMarshal_0-1708977460217.png


^^ with that reference qualifier, no one will be able to enter "Timothy Manager" (for example) into that field. It won't even show up in the list if you search for it.

Thank you for your help, it is something that I know works but due to history criteria this message needs to be displayed through user criteria.

Captura de pantalla 2024-02-26 a las 21.37.46.png

Ah, ok - I'm pretty sure that's specific functionality for a specific "requested for" field type on catalog items, used/defined when building a catalog item. This field happens to be a reference field to the sysuser table, but it's kinda "more than just that".

jMarshal_0-1708982251078.png


I believe you'll need to add custom code to replicate that behaviour on a "regular" sysuser reference field. You'll probably need a client script or 2 and perhaps modify the oob UI Action qualifiers...but shouldn't be too hard.

If you want to use/leverage OOB features only, you can do this by adding the "correct" field type to the catalog item...and then run a fix script to populate it with the data from the "incorrect" field type ("traditional" reference to sysuser field)...and then remove the undesired field from the catalog item.

HTH, GL!

I previously created 2 catalog client scripts and an include script, one to show the alert (which worked correctly for me) and another to cancel sending the form in case the user was "Manager" which gave me an error in the portal. The way to approach it seems not to be correct but I don't know how to replicate it through a User Criteria, here is my dilemma.