Skip to content

Commit 29b88fd

Browse files
authored
Create script.js
1 parent e17c655 commit 29b88fd

File tree

1 file changed

+39
-0
lines changed
  • Client-Side Components/Client Scripts/Auto populate watchlist

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading) return;
3+
4+
// Clear current watch list
5+
g_form.clearValue('watch_list');
6+
7+
// Get values
8+
var openedBy = g_form.getValue('opened_by');
9+
var prevAssigned = oldValue;
10+
var newAssigned = newValue;
11+
12+
// For new records, opened_by might not be set yet
13+
if (!openedBy) {
14+
openedBy = g_user.userID; // current logged-in user
15+
}
16+
17+
// Build watch list
18+
var watchList = [];
19+
20+
if (openedBy) watchList.push(openedBy);
21+
if (prevAssigned) watchList.push(prevAssigned);
22+
if (newAssigned) watchList.push(newAssigned);
23+
24+
// Remove duplicates
25+
var uniqueList = [];
26+
for (var i = 0; i < watchList.length; i++) {
27+
if (uniqueList.indexOf(watchList[i]) === -1) {
28+
uniqueList.push(watchList[i]);
29+
}
30+
}
31+
32+
// Update watch list
33+
if (uniqueList.length > 0) {
34+
g_form.setValue('watch_list', uniqueList.join(','));
35+
}
36+
37+
// Display confirmation message
38+
g_form.addInfoMessage("✅ Assigned To change reflected in Watch list.");
39+
}

0 commit comments

Comments
 (0)