Reference field to Country on sys_user for User Criteria

Stig Brandt2
Mega Expert

Hi

After using user criteria, to limit catalog items to be only avaiable within users specific country, I have encountered that country field is only a string field, and this is also the case in the location table. And User criteria can only be extended for reference field's.

So need to customize the table and add business rules for each implementation that uses catalog across countries, to have this updated to support user criteria, really not very efficient.

Or does anybody have another solution for restricting access to catalog items for a user from a specific country?

And can anyone explain why OOTB the country field on location and sys_user is string fields and not a reference to the country table?

3 REPLIES 3

Deepak Ingale1
Mega Sage

Hi Stig,



I guess you will have to control this via writing down the script in the script section of the user criteria.


Configuring the Script Include which will check the country of the user and then calling it from script section will help you design.



For question related to why country field is a string field.


If you see the hierarchy for locations in servicenow talbe cmn_location, you will find that "Street" has a "Parent" field poining towards another cmn_location table record corresponding to city. This "city" will further have a parent record ponting towards "state". "State" will have a parent record of "country" and so on.



This parent record is a "reference" field.


You can use this field as well in your script to check if either parent or "parent of a parent" is a country which you are looking for.



OR


You can straightaway check the 'country' field which is of type string on the location record which is available as reference field on user record.


Hi Deepak



Thanks for your explanantion/reply



Location is also available on User Criteria, but doesn't support the hierachy, as you explain unless you script, you need to add all Locations to the user criteria, meaning that needs to be updated for every new location added in the system. If User criteria supported the location hierachy - then there is no problem.



User wants to be able to easily create User criteria's not do scripting, as you explain, that is for developers and to have a user criteria based on country code, is pretty obvious as I see it.



It is possible to extend user criterai, to support above, as described below, but fields on user record, needs to be reference fields, which country is not.


User Criteria - ServiceNow Wiki


Hi Stig,



I have not tried the extended user criteria but looking at the explanation provided on the wiki, you will have to add a list type of field poiting towards 'cmn_location' table.


This field is anyways there on the current form but that will not work since you will have to add new location manually everytime it gets created.



So better option is to go with the scripting.



I agree with you that user criteria should be GUI based rather than scripting once, but I would say that this could be the best we can get out of GUI interface. Previously there was entitlement fields which were not that helpful.



For scripting User Criteria, you can take below example.



https://community.servicenow.com/message/783805#783805