- 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:20 PM
Hi KENxx,
Business rules run when a record is displayed, deleted, or updated. See:
https://docs.servicenow.com/search?q=business%20rules
So that approach doesn't seem right for your situation, unless it runs on Display. But where is 'setChoices()' documented? And what is expected when 'contact_type' is changed on a form?
Maybe someone can suggest how you limit a field's values based on the value of another field.