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