- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 03:15 AM
Hello Everyone,
I have written a business rule to update a List type field, without clearing the existing values.
The following script, returns duplicate values to the field. Please suggest how can I overcome this issue.
var users = gr.u_report_viewer.split(',');
if (gr.u_business_sector == 'Performance Materials') {
users.push("bb7fa2110f02da00931d533172050ed6,e526a6910fce9a00931d533172050eaf");
users = new ArrayUtil().unique(users);
gr.u_report_viewer = users.toString();
gr.update();
Thanks In Advance!!
Ramkumar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 03:28 AM
Your users push line is adding one element to the array that looks like 2, so it's not being removed by the unique util, and the toString() conversion along with the List field reading a comma-separated list of IDs is what is causing the duplicates. So your array contains these 3 elements plus others
...
bb7fa2110f02da00931d533172050ed6
e526a6910fce9a00931d533172050eaf
bb7fa2110f02da00931d533172050ed6,e526a6910fce9a00931d533172050eaf
...
Change this to 2 push lines and you will likely not see any more duplicates

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 03:27 AM
Can you try below,
var users = gr.u_report_viewer.split(',');
if (gr.u_business_sector == 'Performance Materials') {
users.push("bb7fa2110f02da00931d533172050ed6,e526a6910fce9a00931d533172050eaf");
} //end if-loop here
users = new ArrayUtil().unique(users);
gr.u_report_viewer = users.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 03:28 AM
Your users push line is adding one element to the array that looks like 2, so it's not being removed by the unique util, and the toString() conversion along with the List field reading a comma-separated list of IDs is what is causing the duplicates. So your array contains these 3 elements plus others
...
bb7fa2110f02da00931d533172050ed6
e526a6910fce9a00931d533172050eaf
bb7fa2110f02da00931d533172050ed6,e526a6910fce9a00931d533172050eaf
...
Change this to 2 push lines and you will likely not see any more duplicates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 03:37 AM
Hey Brad,
Thank you for the answers. It works for me.
Regards,
Ramkumar T