Copy Existing Values and Add New to Watch List onChange

Sofija
Giga Expert

Hi All!

I was hoping maybe someone encountered the same issue or would be able to help regarding watch list.

I currently have client script running to add specified email based on incident priority selected. However, once user chooses to change the priority - the existing watchlist is replaced with the new value defined in the client script.

What I would like it to do is:

1) Replace one email DL with another based on priority

AND

2) Copy all other users added to the watch list which not need to be replaced by the new value

I tried to modify the client script to copy existing value and replace just one of them, but I feel stuck

I hope I am making myself clear, but if no please let me know and I will try to be more detailed and specific

Thank you in advance!

Kamile

1 ACCEPTED SOLUTION

Those should be fine.   It is because I used the same variable names.   You could change the names, or you could pull newWl up to the top and do this:



  1. var wl = g_form.getValue('watch_list');
  2. var newWl = '';
  3.   if (newValue == 1 ) {  
  4.   if(wl.indexOf("email2@email.com") > -1){  
  5.   newWl = wl.replace("email2@email.com", "email@email.com");  
  6.   }else{  
  7.   newWl = wl + ",email@email.com";  
  8.   }  
  9.   /*var alist = g_form.getValue('watch_list');
  10.   var arrlist =   alist.split(",");
  11.   arrlist.push("email@email.com");
  12.   g_form.setValue("watch_list", arrlist);*/  
  13.   g_form.setValue("watch_list", newWl);  
  14.   }  
  15.  
  16.   if (newValue == 2) {  
  17.   if(wl.indexOf("email@email.com") > -1){  
  18.   newWl = wl.replace("email@email.com", "email2@email.com");  
  19.   }else{  
  20.   newWl = wl + ",email2@email.com";  
  21.   }  
  22.   /*var alst = g_form.getValue('watch_list');
  23.   var arrlst =   alst.split(",");
  24.   arrlst.push("email2@email.com");
  25.   g_form.setValue("watch_list", arrlst);*/  
  26.   g_form.setValue("watch_list", newWl);  
  27.   }  

View solution in original post

10 REPLIES 10

edwin_munoz
Mega Guru

Hello Kamile,



First of all, welcome to the community!



You can create an business rule, make it run After Update on the incident table and when priority changes. Copy the current distribution list and add the needed users.



It would look something like this:



current.watch_list = current.watch_list + ',' + getUsersForWatchList();



function getUsersForWatchList(){


// Your logic here to retrieve the user or users. Separate users by commas


// Return the values


}


}



EDIT: If you want this to work client-side then I think your code should work. What happens if you uncomment the lines in the script?



Thank you.



Regards,