Incident reassignment: auto state change + mandatory work notes (multiple conditions)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hello Community,
We have the following requirements on the Incident table and are looking for the best practice approach.
Requirement 1
When an Incident is reassigned to another assignment group (queue)
AND the current state is On Hold
The state should automatically move to In Progress
Work notes must be mandatory during this reassignment
Requirement 2
When an Incident is reassigned to another assignment group (queue)
Irrespective of the current state
Work notes must always be mandatory
I have used this Before update BR - is there in any issue in mu BR
What is the recommended approach to handle both requirements together?
can anyone please help me with this requriment .
please provide us script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi Buddy,
My recommended approach would be a two-layer enforcement.
Use a client-side script for a good user experience immediate feedback in the form and a server-side Business Rule as the real control so the rule is enforced for UI, APIs, integrations and imports.
Server-side Business Rule (main enforcement)
Create a Before Update Business Rule on the Incident table that runs when the assignment group changes.
It ensures work notes are always entered on reassignment and automatically moves the incident from On Hold to In Progress when applicable.
(function executeRule(current, previous) {
if (!current.assignment_group.changes()) {
return;
}
// Work notes are mandatory on any reassignment
if (!current.work_notes.changes()) {
gs.addErrorMessage('Work notes are required when reassigning an Incident.');
current.setAbortAction(true);
return;
}
// If reassigned while On Hold, move to In Progress
if (current.state == '3') { // On Hold
current.state = '2'; // In Progress
}
})(current, previous);This works regardless of how the record is updated and only changes the state when the incident was On Hold.
Client-side (optional, better UX)
Add an onChange Client Script on the assignment_group field to guide users before submit.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == oldValue) {
return;
}
g_form.setMandatory('work_notes', true);
if (g_form.getValue('state') == '3') { // On Hold
g_form.setValue('state', '2'); // In Progress
}
g_form.showFieldMsg(
'work_notes',
'Work notes are required when reassigning an Incident.',
'info'
);
}Even if the client script doesntt run in Service Portal, the Business Rule still enforces the requirement, which is what ultimately matters.
@nameisnani - Please mark Accepted Solution and Thumbs Up if you found Helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Sure and youre very close — the logic is right, there are just a couple of small things that will cause issues.
The main problem is the way work notes are being checked. gs.nil(current.work_notes) doesn’t really work for this use case because work notes are a journal field. That check only tells you whether the field is empty overall, not whether the user added a new work note as part of this update. What you actually want is to make sure a new work note was entered during the reassignment, which means using current.work_notes.changes() instead.
The other tweak is around the state check. It’s safer to compare state values as strings and to look at the current state rather than the previous one, since the requirement is “if the incident is On Hold when it’s reassigned.”
You also don’t strictly need the current.operation() check if this Business Rule is already set to run Before Update.
With those adjustments, your rule becomes simpler and more reliable:
(function executeRule(current, previous) {
// Only run when the assignment group changes
if (!current.assignment_group.changes()) {
return;
}
// Require work notes on any reassignment
if (!current.work_notes.changes()) {
gs.addErrorMessage('Work notes are mandatory when reassigning an incident.');
current.setAbortAction(true);
return;
}
// If the incident is On Hold, move it to In Progress
if (current.state == '3') { // On Hold
current.state = '2'; // In Progress
}
})(current, previous);This will enforce work notes no matter how the incident is updated (UI, API, integration), and it will only move the state when the incident was actually On Hold at the time of reassignment.
@nameisnani - Please mark Accepted Solution and Thumbs Up if you found Helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
My suggestions
1) use client scripts -> so that user knows immediately about mandatory thing
2) use BR -> it will handle list update or API update
-> make work_notes mandatory when group changes using onChange
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) return;
if (newValue != oldValue) {
g_form.setMandatory('work_notes', true);
g_form.addInfoMessage('Work notes are now required for reassignment.');
}
}
-> use onSubmit client script to stop submission
function onSubmit() {
if (g_form.getControl('assignment_group').changed) {
if (g_form.getValue('work_notes') == '') {
g_form.addErrorMessage('Work notes are mandatory when reassigning an incident.');
return false;
}
}
}
-> before BR
(function executeRule(current, previous) {
if (current.operation() !== 'update' || !current.assignment_group.changes()) {
return;
}
// Requirement 2: Enforce work notes (check both current and work_notes list)
var hasWorkNotes = current.work_notes.nil() == false ||
new GlideRecord('sys_journal_field').addQuery('element_id', 'work_notes')
.addQuery('record_sys_id', current.sys_id).getRowCount() > 0;
if (!hasWorkNotes) {
gs.addErrorMessage('Work notes are mandatory when reassigning an incident.');
current.setAbortAction(true);
return;
}
// Requirement 1: On Hold → In Progress
if (previous.state == 3) { // On Hold
current.state = 2; // In Progress
current.update();
}
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
