diff --git a/Client-Side Components/Client Scripts/Auto populate watchlist/README.md b/Client-Side Components/Client Scripts/Auto populate watchlist/README.md new file mode 100644 index 0000000000..783f88730e --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto populate watchlist/README.md @@ -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) + +--- diff --git a/Client-Side Components/Client Scripts/Auto populate watchlist/Screenshot_clientscript_autopopulate_watchlist.png b/Client-Side Components/Client Scripts/Auto populate watchlist/Screenshot_clientscript_autopopulate_watchlist.png new file mode 100644 index 0000000000..f467e56141 Binary files /dev/null and b/Client-Side Components/Client Scripts/Auto populate watchlist/Screenshot_clientscript_autopopulate_watchlist.png differ diff --git a/Client-Side Components/Client Scripts/Auto populate watchlist/script.js b/Client-Side Components/Client Scripts/Auto populate watchlist/script.js new file mode 100644 index 0000000000..5b6f01a753 --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto populate watchlist/script.js @@ -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"); +} diff --git a/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/Incident_Count_message_1.png b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/Incident_Count_message_1.png new file mode 100644 index 0000000000..197c4f9c77 Binary files /dev/null and b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/Incident_Count_message_1.png differ diff --git a/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/Incident_Count_message_2.png b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/Incident_Count_message_2.png new file mode 100644 index 0000000000..719060d503 Binary files /dev/null and b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/Incident_Count_message_2.png differ diff --git a/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/README.md b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/README.md new file mode 100644 index 0000000000..f6d4e8493f --- /dev/null +++ b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/README.md @@ -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) + +--- diff --git a/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/clientScript.js b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/clientScript.js new file mode 100644 index 0000000000..b241347f81 --- /dev/null +++ b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/clientScript.js @@ -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); + } + }); +} diff --git a/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/glideAjax.js b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/glideAjax.js new file mode 100644 index 0000000000..43ef7a81d6 --- /dev/null +++ b/Client-Side Components/Client Scripts/Display Incident Count of Assigned-To User When Field Changes/glideAjax.js @@ -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' +}); diff --git a/Client-Side Components/Client Scripts/Display Message of Incident Count When Changing Assigned To/clientscript.js b/Client-Side Components/Client Scripts/Display Message of Incident Count When Changing Assigned To/clientscript.js new file mode 100644 index 0000000000..b241347f81 --- /dev/null +++ b/Client-Side Components/Client Scripts/Display Message of Incident Count When Changing Assigned To/clientscript.js @@ -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); + } + }); +} diff --git a/Client-Side Components/Client Scripts/Display Message of Incident Count When Changing Assigned To/glideAjax.js b/Client-Side Components/Client Scripts/Display Message of Incident Count When Changing Assigned To/glideAjax.js new file mode 100644 index 0000000000..43ef7a81d6 --- /dev/null +++ b/Client-Side Components/Client Scripts/Display Message of Incident Count When Changing Assigned To/glideAjax.js @@ -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' +});