Skip to content

Commit 78c2bcd

Browse files
authored
Update script.js
1 parent 5854121 commit 78c2bcd

File tree

1 file changed

+10
-13
lines changed
  • Client-Side Components/Client Scripts/Auto populate watchlist

1 file changed

+10
-13
lines changed
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
22
if (isLoading) return;
33

4-
// Clear current watch list
5-
g_form.clearValue('watch_list');
4+
// Get existing watch list first
5+
var existing = g_form.getValue('watch_list');
6+
var watchList = existing ? existing.split(',') : [];
67

7-
// Get values
8+
// Get key values
89
var openedBy = g_form.getValue('opened_by');
910
var prevAssigned = oldValue;
1011
var newAssigned = newValue;
1112

12-
// For new records, opened_by might not be set yet
1313
if (!openedBy) {
1414
openedBy = g_user.userID; // current logged-in user
1515
}
1616

17-
// Build watch list
18-
var watchList = [];
19-
17+
// Add new users if not already present
2018
if (openedBy) watchList.push(openedBy);
2119
if (prevAssigned) watchList.push(prevAssigned);
2220
if (newAssigned) watchList.push(newAssigned);
2321

2422
// Remove duplicates
2523
var uniqueList = [];
2624
for (var i = 0; i < watchList.length; i++) {
27-
if (uniqueList.indexOf(watchList[i]) === -1) {
28-
uniqueList.push(watchList[i]);
25+
var val = watchList[i];
26+
if (val && uniqueList.indexOf(val) === -1) {
27+
uniqueList.push(val);
2928
}
3029
}
3130

3231
// Update watch list
33-
if (uniqueList.length > 0) {
34-
g_form.setValue('watch_list', uniqueList.join(','));
35-
}
32+
g_form.setValue('watch_list', uniqueList.join(','));
3633

3734
// Display confirmation message
38-
g_form.addInfoMessage("Assigned To change reflected in Watch list.");
35+
g_form.addInfoMessage(" Your Assigned To change is reflected and added in Watch list");
3936
}

0 commit comments

Comments
 (0)