- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 07:48 AM
Hi I have added new choices for On Hold Reason
1. awaiting delivery
2. awaiting payment
3. awaiting contractor
and I want them to be visible only when the category is facilities and should be hidden for other categories.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:54 AM - edited 11-30-2023 09:47 AM
I was able to achieve this on my PDI for both scenarios.
1. Wrote down a onChange client script on Category field & put following code into it
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') {
return;
}
if (isLoading && oldValue != 'inquiry') { ///update with backend value of Facilities choice here
g_form.removeOption('hold_reason', '1'); //update with backend value of choices which you don't want to see on other categories
g_form.removeOption('hold_reason', '5');
return;
}
if (newValue === 'inquiry') { //update with backend value of Facilities choice here
g_form.addOption('hold_reason', '1', 'Awaiting Caller'); //update the backend & front-end labels here which you only want to see in facilities category
g_form.addOption('hold_reason', '5', 'Awaiting Change');
return;
}
g_form.removeOption('hold_reason', '1');
g_form.removeOption('hold_reason', '5');
}
2. Do make sure you update the backend values & front-end values of the choices.
3. In my scenario, I am hiding choices on all other categories apart from 'Inquiry' category. It should work.
Do mark this response as CORRECT / HELPFUL as it will help others & will motivate me as well to write more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:52 AM
It's clearValue, it's not used to remove options.
I was intended to set the On Hold Reason back to None when the Category is changes to empty. You can remove that line.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:01 AM
Follow the same way as followed in Incident
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
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/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 09:02 AM
HI @Rahul Raja Sami ,
I trust youa re doing great.
Please find the below reference script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var reasonField = g_form.getField('on_hold_reason'); // Replace with actual field name
var facilitiesCategoryValue = 'facilities'; // Replace with the actual value for the facilities category
// Check if the category is 'facilities'
if (newValue == facilitiesCategoryValue) {
// Show the options
reasonField.enableOption('awaiting delivery');
reasonField.enableOption('awaiting payment');
reasonField.enableOption('awaiting contractor');
} else {
// Hide the options
reasonField.disableOption('awaiting delivery');
reasonField.disableOption('awaiting payment');
reasonField.disableOption('awaiting contractor');
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi