Business Rule to update a List type field.

Ramkumar Thanga
Mega Sage

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

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

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

 

View solution in original post

3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

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();

Brad Bowman
Kilo Patron
Kilo Patron

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

 

Ramkumar Thanga
Mega Sage

Hey Brad,

Thank you for the answers. It works for me. 

 

Regards,

Ramkumar T