Catalog user Criteria

Rooma1
Tera Contributor

Hi All,

I have been asked a question in the Interview : How I can restrict the Catalog Item for the users which are from 'America' location?

I answered like we can restrict it through the user criteria via location field.

Then the next counter question was suppose i want to script it then how can you achieve it?

Can someone please help me how to restrict via script in User criteria?

 

Thanks,

Rooma

3 REPLIES 3

Sonam_Tiwari
Kilo Sage

Hey,

 

Check this thread out - https://www.servicenow.com/community/itsm-forum/how-to-restrict-catalog-item-for-user-country/td-p/7...

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

OlaN
Giga Sage
Giga Sage

Hi,

Not sure if the counter question is a trick question. Why would you want to script a user criteria if it can be done via setting the location field?

It can be done, and I believe the best way would be to do it by calling a script include, that returns true if the user is located in 'America'.

Then the user criteria script would look something like this:

// passing user_id to the function will contain the logged in users UserID.
answer = new YourScriptIncludeName().yourFunctionName(user_id);

// the script include would be kind of simple too, something like this:
yourFunctionName: function(userId){
  var userGR = new GlideRecord('sys_user');
  if (userGR.get(userId){
    if (/*your condition to find out if the user has America location*/){
        return true;
    }
    else{
      return false;
      }
  }
  else{
    // user not found
    return false;
    }
},

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Rooma1 

 

The first way is User criteria only which is  no code / low code way. You can restrict via Script but only when you did not find way in OOTB way.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************