Make comments mandatory when state changes in incident

Luke James
Tera Contributor

Hi All, 

 

I have the following requirement. 

 

I am mandated to update the Additional Comments field when:

  • I move an Incident into Cancelled state
  • I move an Incident from On hold into In Progress state for On hold reason Awaiting Caller
  • I move an Incident from Resolved to In Progress

How would be best to do this in ServiceNow? I thought UI policy, but how would a UI policy manage the changing of the states? 

 

Kind Regards, 

 

Luke

5 REPLIES 5

Bert_c1
Kilo Patron

You can use use a Client Script, see examples in your instance. Once that is not Active OOB is "Make Mandatory". Use the following in the instance URL: sys_class_name=sys_script_client^nameLIKEmandatory

Thanks very much for your response. 

 

Problem i'm having with a client script is that it is not changing on the first time the value is changed. Only the 2nd time the field value is changed? 

 

Do you know why this might be? 

Hi Luke,

 

You need to post the Client Script. Is the Type 'onChange' for the 'state' field?  Provide details then myself or others here can assist you.  The client script named "Make Additional comments mandatory" defined on the kb_knowledge table, as an example.

Maddysunil
Kilo Sage

@Luke James 

I think you need to write 3 on change client script, below is the script:

1. Moving an Incident into Cancelled State:

 

    var currentState = g_form.getValue('incident_state');//validate the field
    if (currentState == '7') { // 7 is the state for "Cancelled"
        g_form.setValue('additional_comments', 'Incident moved to Cancelled state.');
    }

 

 

2. Moving an Incident from On Hold into In Progress State for On Hold Reason "Awaiting Caller":

 

    var currentState = newValue;
    var previousState = oldValue;
    var currentOnHoldReason = g_form.getValue('on_hold_reason');
    if (currentState == '2' && previousState == '4' && currentOnHoldReason == 'Awaiting Caller') { // 2 is "In Progress", 4 is "On Hold"
        g_form.setValue('additional_comments', 'Incident moved from On Hold (Awaiting Caller) to In Progress.');
    }

 

 

3. Moving an Incident from Resolved to In Progress

 

function onChange_ResolvedToInProgress() {
    var currentState = newValue;
    var previousState = oldValue;
    if (currentState == '2' && previousState == '6') { // 2 is "In Progress", 6 is "Resolved"
        g_form.setValue('additional_comments', 'Incident moved from Resolved to In Progress.');
    }
}

 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.