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

Gunjan Kiratkar
Kilo Patron
Kilo Patron

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

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

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

This worked, thank you so much for your assistance!