Copy HRBP field values in Customer WatchList using BR

Harsha1
Tera Contributor

Hi Community,
Hope you all are doing great.
I am facing issue while coping the values from HRBP field to Customer Watchlist.

HRBP is also a list collector field.

1.Issue using BR

if the customer watchlist is blank, it will not coping the values from HRBP field.
There is one BR also running which is adding Customer watchlist automatically for few particular HR service. In this condition when I am adding HRBP it is coping all the values in Customer watchlist.

 

Before, Insert/Update

Condition  active is True AND HRBP is changes

Script -

(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(',');
gs.info("harsha arr" + arr);
for (var i = 0; i < arr2.length; i++) {
if (watchList.indexOf(arr2[i]) == -1) {
gs.info("harsha arr" + arr);
arr.push(arr2[i]);
}
}


current.watch_list = arr.join();

 

})(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.

 

Script-

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);
    }
 
 
}
 
I tried to modify the client script and Business Rule. Still it is not working. Is there any suggestion where I have to modify the script.
 
Thanks & Regards,
Harsha.
1 REPLY 1

Ratnakar7
Mega Sage
Mega Sage

Hi @Harsha1 ,

 

Please try with below updated BR and Client Script:
Business Rule: 

(function executeRule(current, previous /*null when async*/) {
    var arr = current.watch_list ? current.watch_list.split(',') : [];
    var hrbp = current.u_hrbp;
    var arr2 = hrbp.split(',');
    
    for (var i = 0; i < arr2.length; i++) {
        if (arr.indexOf(arr2[i]) == -1) {
            arr.push(arr2[i]);
        }
    }
    
    current.watch_list = arr.join();
})(current, previous);

Client Script: 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    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" || /* ...other conditions... */) {
        var arrlist = watchList ? watchList.split(",") : [];
        arrlist.push(hrbp);
        g_form.setValue("watch_list", arrlist.join());
    }
}

 

Thanks,

Ratnakar