Require additonal comments when incident is cancelled

Patrick Slatter
Tera Guru

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!

 

 

1 ACCEPTED SOLUTION

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.

GunjanKiratkar_0-1673528733346.png

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

5 REPLIES 5

where to add the above script?