Make comments mandatory when state changes in incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 01:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 01:40 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 01:55 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 02:59 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 06:54 PM
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.