- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 04:33 AM - edited 01-12-2023 04:41 AM
Morning!
I am trying to make additonal comments required when an incident is cancelled, however i am experiancing some strange behaviour.
Client script OnChange
UI type = ALL
Field = State
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// var state = g_form.getValue('state');
if (newValue == 8 ) {
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments',"Additional comments are required when cancelling an incident.");
}
}
When this runs it pops up the additonal comments field, however it is not required.
Example of odd behaviour:
If it is in a new state, and i change to cancelled, nothting happens. If it is in a new state, i change to work in progress then change to cancelled (all before saving) then the field does become required.
Any assistance would be greatly appriciated.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 05:06 AM
Search this UI policy on incident table and uncheck the reverse if false or add your state condition in that UI policy it self. This UI policy is conflicting your Client script logic.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 04:40 AM
Hi @Patrick Slatter ,
Try below Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// var state = g_form.getValue('state');
if (newValue == '8') {
g_form.setVisible('work_notes', false);
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments', "Additional comments are required when cancelling an incident.");
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 04:46 AM
Thank you for the prompt response @Gunjan Kiratkar !
I tried this and am experiancing the same behaviour.
If i open an incident that is in a new state and change the state value from new to cancelled, it pops up the additonal comments field but is not required.
If i open that same incident that is in a new state, change it to work in progress then change it to cancelled (all before saving) then the adidtonal comments becomes required.
Same behaviour with both my and your script.
Any ideas? Thanks again for your help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 05:06 AM
Search this UI policy on incident table and uncheck the reverse if false or add your state condition in that UI policy it self. This UI policy is conflicting your Client script logic.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 05:10 AM
This worked, thank you so much for your assistance!