|
1 | 1 | function onChange(control, oldValue, newValue, isLoading, isTemplate) { |
2 | 2 | if (isLoading) return; |
3 | 3 |
|
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(',') : []; |
6 | 7 |
|
7 | | - // Get values |
| 8 | + // Get key values |
8 | 9 | var openedBy = g_form.getValue('opened_by'); |
9 | 10 | var prevAssigned = oldValue; |
10 | 11 | var newAssigned = newValue; |
11 | 12 |
|
12 | | - // For new records, opened_by might not be set yet |
13 | 13 | if (!openedBy) { |
14 | 14 | openedBy = g_user.userID; // current logged-in user |
15 | 15 | } |
16 | 16 |
|
17 | | - // Build watch list |
18 | | - var watchList = []; |
19 | | - |
| 17 | + // Add new users if not already present |
20 | 18 | if (openedBy) watchList.push(openedBy); |
21 | 19 | if (prevAssigned) watchList.push(prevAssigned); |
22 | 20 | if (newAssigned) watchList.push(newAssigned); |
23 | 21 |
|
24 | 22 | // Remove duplicates |
25 | 23 | var uniqueList = []; |
26 | 24 | 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); |
29 | 28 | } |
30 | 29 | } |
31 | 30 |
|
32 | 31 | // 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(',')); |
36 | 33 |
|
37 | 34 | // 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"); |
39 | 36 | } |
0 commit comments