- 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 - last edited yesterday
I am bit confused.
If you can see the selected location.png, a city was selected and there is a button to preview record. When clicking on it, shows the record with fields of it, country.png. I was trying to verify if the previewed record value i.e country is of USA or not. Can we dot walk only for once?
As this can not be done via UI policy, i was checking if i could achieve just with Catalog client script.
- 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
6 hours ago
Can we continuously check for the variables and dynamically make the field visible?
if 1st and 2nd fields are selected, then 3rd is visible.
if 1st is unchecked, still the 3rd is visible.
However, when 2nd is unchecked, 3rd is being hidden.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
you will require onchange scripts on other variables also to handle this
I believe I answered your original question.
💡 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,
Follow below steps to build this:
Create a catalog variable
Name: country
Hidden: true
Auto‑populate from the reference variable country field (var_reference.country).
Create a UI Policy
Condition: country is USA.
UI Policy Action: Set var_selectbox to Visible = true.
Thanks
Anand