Is it possible to display only one field option to users in the US location.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 03:05 AM - edited 03-31-2025 01:14 AM
Is it possible to display only one field option to users in the US location, while making all other options visible to users in other locations?
For example, only the wireless option should be visible to the US location users.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 03:18 AM
Hi @Ria
Yes, you need to hide the choice values based on the user's location. Write a Catalog Client Script.
Try something like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getValue('name');
if(name=='payments'||name=='invoice'||name=='statement'){
g_form.clearOptions('status');
g_form.removeOption('status', '3rd Party');
}
if(name=='card){
g_form.clearOptions('status');
g_form.addOption('status', '3rd Party');
}
}
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 03:44 AM
you can use onLoad client script + GlideAjax
Script Include: It should be client callable
var UserLocationChecker = Class.create();
UserLocationChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// This function checks if the user's location is 'US'
checkUserLocation: function() {
var userGR = new GlideRecord('sys_user');
if (userGR.get(gs.getUserID())) {
return userGR.location.name.toString() == 'US';
}
return false;
},
type: 'UserLocationChecker'
});
onLoad client script:
function onLoad() {
var ga = new GlideAjax('UserLocationChecker');
ga.addParam('sysparm_name', 'checkUserLocation');
ga.getXMLAnswer(function(response) {
// if US then remove wired option
if (response.toString() == 'true')
g_form.removeOption('type', 'wired'); // give the correct field name or variable name and the choice value
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 04:04 AM - edited 03-28-2025 04:12 AM
Hello @Ria ,
You can also achieve this with minimal scripting.
Step 1: Have a variable for the User, Location, and the Type, like this:
Step 2: Configure the Location variable to get auto populated based on the User location:
Step 3: Create a UI Policy with the Condition "Location = US" and the following script:
If true:
function onCondition() {
g_form.removeOption('type', 'wired');
}
If false:
function onCondition() {
g_form.addOption('type', 'wired', 'wired');
}
If you don't actually require the User and Location variables to be visible on your form you can enable the "Hidden" checkbox on them.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 05:10 AM
Hi @Robert H
We already have a 'Site' field available on the catalog item. I have created a UI policy with above-mentioned script and condition as 'Site' is US. It's not working as expected and getting the below error when a UI policy is created.
Regards,
Riya Jain