Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Automatically Populate Watch List When Assigned-To Changes

When the **Assigned To** field changes, this client script updates the **Watch list** to include the **Opened By**, **previous assignees**, and **new assignee**.
- Help maintains visibility of all users involved on incident record.
- Helps track assigned-to transitions and ensures clarity during assignment change.
- A confirmation message appears when the change is reflected in the Watch list.
- Specific script for use in the Incident record form in ServiceNow but can be used for other record forms too.
---

![Auto populate watchlist](./Screenshot_clientscript_autopopulate_watchlist.png)

---
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) return;

// Get existing watch list first
var existing = g_form.getValue('watch_list');
var watchList = existing ? existing.split(',') : [];

// Get key values
var openedBy = g_form.getValue('opened_by');
var prevAssigned = oldValue;
var newAssigned = newValue;

if (!openedBy) {
openedBy = g_user.userID; // current logged-in user
}

// Add new users if not already present
if (openedBy) watchList.push(openedBy);
if (prevAssigned) watchList.push(prevAssigned);
if (newAssigned) watchList.push(newAssigned);

// Remove duplicates
var uniqueList = [];
for (var i = 0; i < watchList.length; i++) {
var val = watchList[i];
if (val && uniqueList.indexOf(val) === -1) {
uniqueList.push(val);
}
}

// Update watch list
g_form.setValue('watch_list', uniqueList.join(','));

// Display confirmation message
g_form.addInfoMessage(" Your Assigned To change is reflected and added in Watch list");
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Display Info Message of Incident Count of Assigned-To User When Field Assigned-To Changes

Displays a message showing the count of **open incidents** assigned to a user whenever the **Assigned To** field changes on the Incident form.

- Helps assess the assignee’s **current workload** by fetching and displaying active incident counts (excluding *Resolved*, *Closed*, and *Canceled* states)
- Shows an **info message** with the count of the assignee's assigned incidents
- Uses an **onChange Client Script** on the **Assigned To** field and a **GlideAjax Script Include** called from the client script to fetch the count dynamically

---

### Info Message Example 1
![Incident_Count_message_1](Incident_Count_message_1.png)

---

### Info Message Example 2
![Incident_Count_message_2](Incident_Count_message_2.png)

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') return;

// Clear any previous messages
g_form.clearMessages();

// Create GlideAjax object to call the Script Include
var ga = new GlideAjax('IncidentAssignmentCheck');
ga.addParam('sysparm_name', 'getIncidentCount');
ga.addParam('sysparm_user', newValue);


ga.getXMLAnswer(function(response) {
var count = parseInt(response, 10);


if (isNaN(count)) {
g_form.addErrorMessage("Could not retrieve open incident count.");
return;
}

var userName = g_form.getDisplayValue('assigned_to');
var msg = userName + " currently has " + count + " incidents assigned ";

if (count >= 5) {
g_form.addInfoMessage(msg + " Please review workload before assigning more incidents");
} else {
g_form.addInfoMessage(msg);
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var IncidentAssignmentCheck = Class.create();
IncidentAssignmentCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getIncidentCount: function() {
var user = this.getParameter('sysparm_user');
var count = 0;

if (user) {
var gr = new GlideAggregate('incident');
gr.addQuery('assigned_to', user);
gr.addQuery('state', 'NOT IN', '6,7,8');
gr.addAggregate('COUNT');
gr.query();

if (gr.next()) {
count = gr.getAggregate('COUNT');
}
}
return count;
},

type: 'IncidentAssignmentCheck'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') return;

// Clear any previous messages
g_form.clearMessages();

// Create GlideAjax object to call the Script Include
var ga = new GlideAjax('IncidentAssignmentCheck');
ga.addParam('sysparm_name', 'getIncidentCount');
ga.addParam('sysparm_user', newValue);


ga.getXMLAnswer(function(response) {
var count = parseInt(response, 10);


if (isNaN(count)) {
g_form.addErrorMessage("Could not retrieve open incident count.");
return;
}

var userName = g_form.getDisplayValue('assigned_to');
var msg = userName + " currently has " + count + " incidents assigned ";

if (count >= 5) {
g_form.addInfoMessage(msg + " Please review workload before assigning more incidents");
} else {
g_form.addInfoMessage(msg);
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var IncidentAssignmentCheck = Class.create();
IncidentAssignmentCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getIncidentCount: function() {
var user = this.getParameter('sysparm_user');
var count = 0;

if (user) {
var gr = new GlideAggregate('incident');
gr.addQuery('assigned_to', user);
gr.addQuery('state', 'NOT IN', '6,7,8');
gr.addAggregate('COUNT');
gr.query();

if (gr.next()) {
count = gr.getAggregate('COUNT');
}
}
return count;
},

type: 'IncidentAssignmentCheck'
});
Loading