- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 05:47 PM - edited 02-05-2024 05:49 PM
Hello, teams
I have a question about businessrule.
We have a requirement to show choices "u_substatus" by what "contact_type" is.
For example, when "contact_type" is "system-error" we want to show "u_substatus" choices('1', '2').
When "contact_type" is "report" we want to show "u_substatus" choices('3', '4').
I made a businessrule and wrote a script below, but didn't work.
Any suggestion, that would be so helpful.
Thanks.
★When to run
▼When after
▼Filter Conditions
Contact type is System-error
or Contact type is Report
★Advanced
▼Script
(function executeRule(current, previous /*null when async*/ ) {
// Show substatus choices by contact types
var fieldOptions = [];
if (current.contact_type == 'system-error') {
fieldOptions = ['1', '2'];
} else if (current.contact_type == 'report') {
fieldOptions = ['3', '4'];
}
current.u_substatus.setChoices(fieldOptions);
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Customer Service Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 09:13 PM
Hi @KENxx adjusted the code accordinlgy
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Remove substatus choices by contact types
g_form.clearOptions('u_substatus');
if (newValue == 'system-error') {
g_form.addOption('u_substatus', '20', 'Control confirmation');
g_form.addOption('u_substatus', '21', 'Under development request');
} else if (newValue == 'report')
g_form.addOption('u_substatus', '22', 'Under development analysis');
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 06:04 PM
Hi @KENxx to show or hide choices Client script is the way to do because choice needs to be displayed upon changing the value where as Business rule will not work until you hit update.
Refer doc below
https://developer.servicenow.com/dev.do#!/search/vancouver/All/addOption/
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 09:05 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 09:13 PM
Hi @KENxx adjusted the code accordinlgy
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Remove substatus choices by contact types
g_form.clearOptions('u_substatus');
if (newValue == 'system-error') {
g_form.addOption('u_substatus', '20', 'Control confirmation');
g_form.addOption('u_substatus', '21', 'Under development request');
} else if (newValue == 'report')
g_form.addOption('u_substatus', '22', 'Under development analysis');
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 09:50 PM
Thank you for the answer, Mr.Harish.
It did work properly.
It was so helpful.
Thank you again.
Best Regards,