Incident Form - Resolution Code choices visibility
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hello Community,
I have a very basic requirement, but it seems I am not getting the required output even after multiple trials.
I have a field called 'Resolution code' (close_code) on the Incident form. It has 8 options. My requirement was to hide the options 5-8 when the incident state is not canceled. So, whenever someone opens a new or existing record, these options should remain hidden. This was achieved properly by using onLoad Client script.
Now the main issue is because of requirement no. 2. When the state change to Canceled in real time, the options 5-8 should get visible and the options 1-4 should now get hidden/removed from the list. I have tried multiple script to achieve this but to no avail. It is getting stuck at a point.
Kindly share your expertise in resolving this issue. Thank you for your guidance and support on this. Much appreciated.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @AakankshaSK
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
24m ago
Hi @AakankshaSK ,
Choice list options are cached on the client, so hiding options only on form load is not enough. When the State field changes in real time, the Resolution Code list does not automatically refresh.
To handle this properly, you must clear and rebuild the choice list whenever the form loads and whenever the State changes.
Recommended Solution
Use onLoad + onChange Client Scripts and dynamically rebuild the choices using g_form.clearOptions() and g_form.addOption().
Step 1: onLoad Client Script
Table: Incident
Type: onLoad
function onLoad() {
updateCloseCodeChoices();
}
Step 2: onChange Client Script (on State)
Table: Incident
Field: state
Type: onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
updateCloseCodeChoices();
}
Step 3: Shared Function (UI Script or Global Client Script)
function updateCloseCodeChoices() {
var state = g_form.getValue('state');
// Update with your actual choice values
var activeChoices = ['1','2','3','4'];
var cancelChoices = ['5','6','7','8'];
// Clear existing options
g_form.clearOptions('close_code');
// Check Canceled state value in your instance
if (state == '7') { // Example: 7 = Canceled
// Show only cancel-related choices
cancelChoices.forEach(function(val) {
g_form.addOption('close_code', val, val);
});
} else {
// Show only active choices
activeChoices.forEach(function(val) {
g_form.addOption('close_code', val, val);
});
}
// Remove invalid existing value
var currentValue = g_form.getValue('close_code');
if ((state == '7' && activeChoices.includes(currentValue)) ||
(state != '7' && cancelChoices.includes(currentValue))) {
g_form.clearValue('close_code');
}
}
Please note:
Always use choice values, not labels.
Verify the actual value of the Canceled state in:
If this helps you then mark it as helpful and accept it as solution.
