adding users from one list to another list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 06:18 AM
Hi Community,
Hope you all are doing great.
I am facing issue while coping the values from a custom list collector user field to Customer Watchlist.
we have tried the solution two ways client side & server side both are as below.
1.Issue using BR
if the customer watchlist is blank, it will not coping the values from custom field.
however if there is already a value in watchlist (due to another BR) , it will add the new values form custom to watchlist . when users are selected on custom list .
Before, Insert/Update
Condition active is True AND HRBP is changes
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var arr = current.watch_list.split(',');
var watchList = current.watch_list;
var hrbp = current.u_hrbp;
var arr2 = hrbp.split(',');
if (watchList != null) {
for (var i = 0; i < arr2.length; i++) {
if (watchList.indexOf(arr2[i]) == -1) {
arr.push(arr2[i]);
}
current.watch_list = arr.join();
}
} else {
current.watch_list = hrbp;
}
})(current, previous);
})(current, previous);
2.Issue using Client script.
And in the Client Script it is Coping all the values from HBBP field, But after saving the form it is setting only one user. Here that another one BR is overriding.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var newWl = '';
var hrbp = g_form.getValue('u_hrbp');
//var watchList = g_form.getValue('watch_list');
var hrService = g_form.getValue('hr_service');
if (hrService == "4d52355f871fa11027cb65373cbb353f" || hrService == "282c18021b97e1945ed35533604bcba9" || hrService == "b3d3eb631b26a11036d954a51a4bcb4f" || hrService == "7aed88f8877fe11427cb65373cbb35ed" || hrService == "5bde0c4e1b93e1945ed35533604bcb7b" || hrService == "db57880a1b53e1945ed35533604bcb47") {
//alert("harsha in else loop");
newWl = hrbp ;
var alist = g_form.getValue('watch_list');
var arrlist = alist.split(",");
arrlist.push(newWl);
g_form.setValue("watch_list",arrlist);
// g_form.setValue("watch_list", newWl);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 07:24 AM
Hello @Karanpreet ,
In the First BR, Instead of Using " if (watchList != null) " Change it with " if(watchList != '') ".

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 07:41 AM
Hi Karanpreet,
Can you try below in BR
(function executeRule(current, previous /*null when async*/ ) {
var arr = current.watch_list.split(',');
var finalarr='';
for(var i=0;i<arr.length;i++)
{
finalarr=arr[i]+','+finalarr;
}
current.hrbp=finalarr;//considering hrbp is the field you wish to update
current.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 07:59 PM
Your problem is you are trying to "split" a null value into an array right on your first line. I could have re-worked your logic around to make it work, but I prefer to use the ArrayUtil class when dealing with arrays. It can simplify your code to something like this:
(function executeRule(current, previous /*null when async*/) {
//instantiate an empty array if the current lists are empty
var watchList = current.watch_list.nil() ? [] : current.getValue("watch_list").split(",");
var hrbpList = current.u_hrbp.nil() ? [] : current.getValue("u_hrbp").split(",");
var arrayUtil = new global.ArrayUtil();
var newWatchList = arrayUtil.concat(watchList, hrbpList); //combine both arrays
current.watch_list = arrayUtil.unique(newWatchList).join(","); //then grab just the unique entries
})(current, previous);
I tried it with the Watch list and Work notes list on the Incident table then used your field name when I pasted the code here. It should be fine.