- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have 5 business area on when user select on of them specific variable will be display with their own choice.
Example business area = a1,a2,a3,a4,a5
for all of them we have separate type of request with own choices
how do i configure show or hide it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
you can use onChange catalog client script on that business area variable and then show/hide other variables
it's an easy requirement
what did you start with and where are you stuck?
something like this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading)
return;
// hide all variables
g_form.setDisplay('a1_var1', false);
g_form.setDisplay('a2_var1', false);
g_form.setDisplay('a3_var1', false);
g_form.setDisplay('a4_var1', false);
g_form.setDisplay('a5_var1', false);
if (newValue == 'a1') {
g_form.setDisplay('a1_var1', true);
// show whichever you want
} else if (newValue == 'a2') {
g_form.setDisplay('a2_var1', true);
// show whichever you want
}
// etc.
}
💡 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
in that case you can use g_form.removeOption(), g_form.addOptions(), g_form.clearOptions()
// Catalog Client Script (onChange) on variable: business_area
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
// clear all existing options
g_form.clearOptions('request_type');
// always add a default None option
g_form.addOption('request_type', '', '-- None --');
if (newValue == 'a1') {
g_form.addOption('request_type', 'a1_opt1', 'Choice Label 1');
g_form.addOption('request_type', 'a1_opt2', 'Choice Label 2');
} else if (newValue == 'a2') {
g_form.addOption('request_type', 'a2_opt1', 'Choice Label 3');
g_form.addOption('request_type', 'a2_opt2', 'Choice Label 4');
g_form.addOption('request_type', 'a2_opt3', 'Choice Label 5');
} else if (newValue == 'a3') {
g_form.addOption('request_type', 'a3_opt1', 'Choice Label 6');
} else if (newValue == 'a4') {
g_form.addOption('request_type', 'a4_opt1', 'Choice Label 7');
g_form.addOption('request_type', 'a4_opt2', 'Choice Label 8');
} else if (newValue == 'a5') {
g_form.addOption('request_type', 'a5_opt1', 'Choice Label 9');
}
}
💡 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
2 hours ago
Hi @RoshaniB ,
@Ankur Bawiskar script will work perfectly on requirement you posted earlier
Now what you are asking now is a different requirement, because you also want to show or hide additional variables based on the selected request type. For that, you will need a second on-Change script. So overall, you need two scripts: script-1 to control the dependent dropdown choices, and script-2 to display the correct variable based on the user’s selection.
Is my assumption correct, if not kindly correct it.
Thanks and Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
this script will work? for scenario like example
variable= business-drop down choices -General, It, OT (if general was selected then type of request will be show choices with only specific options)
variable=type of request-drop down choices - generic, account, bug (if type of request is generic on the basis of business area then below specific variable will show)
variable=what are you trying to do?
variable=bug error
variable=link to ot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @RoshaniB ,
@Ankur Bawiskar script will work perfectly on requirement you posted earlier
Now what you are asking now is a different requirement, because you also want to show or hide additional variables based on the selected request type. For that, you will need a second on-Change script. So overall, you need two scripts: script-1 to control the dependent dropdown choices, and script-2 to display the correct variable based on the user’s selection.
Is my assumption correct, if not kindly correct it.
Thanks and Regards,
Mohammed Zakir
