- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Lets assume there are three variables.
1. var_checkbox - true/false
2. var_reference - fetches city locations
3. var_selectbox - Several question choices. By default, variable is hidden.
in a catalog item.
When checkbox is true and reference's location's country (lets say USA), then the selectbox should be visible.
I was thinking of using getReference method to get the country name from the city using catalog client script, not sure if it will return display value from that record or sys_id.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
g_form.getReference('var_reference', function(cityObj) {
g_form.setDisplay(
'var_selectbox',
g_form.getValue('var_checkbox') === 'true' && cityObj && cityObj.country && (cityObj.country.name === 'United States' || cityObj.country.name === 'USA' || cityObj.country.name === 'United States (USA)')
);
});
}Is there any way to use via UI policy?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
then you can use getReference with callback and dot walk and get Country value and then compare
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ref = g_form.getReference('var_reference', callBackMethod); // your reference variable name
}
function callBackMethod(ref) {
var country = ref.country.toString();
g_form.setDisplay('var_selectbox', g_form.getValue('var_checkbox') === 'true' && (country == 'United States' || country == 'USA' || country == 'United States (USA)'));
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
hi @Kvb Kiran
no you cant do this via ui policy, because ui policy was designed to handle actions based on conditions of fields directly on the current form's record.
My Custom solution based on your requirement is to create a hidden variable of type to Single Line Text and in the Type Specifications tab, set Hidden to True .
Modify client scrpt (onChange of var_reference)
current_country is the hidden variable name, chnge it accordingly
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
g_form.setValue('current_country', '');
return;
}
g_form.getReference('var_reference', function(cityObj) {
if (cityObj && cityObj.country) {
var countryDisplayValue = cityObj.country.getDisplayValue() || cityObj.country;
g_form.setValue('current_country', countryDisplayValue);
} else {
g_form.setValue('current_country', '');
}
});
}
now use the new variable value in the ui policy filter conditions
Happy to help! If this resolved your issue, kindly mark it as the correct answer ✅ and Helpful and close the thread 🔒 so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi Deepak,
Did you mean, use the variable "countryDisplayValue" in a UI policy? Should i use the client script in run script of a UI policy?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
if reference variable holds exact country like USA, United States etc then this will work
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
try {
if (window == null) {
var countryPortalValue = g_form.getDisplayValue('var_reference');
g_form.setDisplay('var_selectbox', g_form.getValue('var_checkbox') === 'true' && (countryPortalValue == 'United States' || countryPortalValue == 'USA' || countryPortalValue == 'United States (USA)'));
}
} catch (ex) {
var countryNativeValue = g_form.getDisplayBox('var_reference').value;
g_form.setDisplay('var_selectbox', g_form.getValue('var_checkbox') === 'true' && (countryNativeValue == 'United States' || countryNativeValue == 'USA' || countryNativeValue == 'United States (USA)'));
}
//Type appropriate comment here, and begin script below
}
I created blog as well on how to get display value of reference variable in catalog both native + portal
Get Display value of reference variable Service Catalog
If you are talking about 1 more dot walk level then you will have to use GlideAjax
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Thank you for marking my response as helpful.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader