The CreatorCon Call for Content is officially open! Get started here.

Add Callers manager to watch list

alhicks
Tera Guru

We're needing to add the callers manager to the incident watch list, if the caller_id.u_cs_home_agent check flag is true.       I've tried a few scripts that I've found on the community but cannot seem to get it working. Tried business rule on before and after.   Tried with a condition and without.

current.caller_id.u_cs_home_agent == "true"

    addToWatchList();  
function addToWatchList() {  

current.watch_list += current.caller_id.manager;  

 

var gr = new GlideRecord('sys_user');  
gr.addQuery('name',current.caller_id.manager);  
gr.query();  
while(gr.next())  
  {  
              var user =(','+ gr.user);  
              current.watch_list += user;  
      }  
}  

}

1 ACCEPTED SOLUTION

Andras Kisgyorg
Kilo Guru

HI Andrea,



It should be a before update business rule, and you can leave the condition in place but remove the apostrophes from "true" check as it validates the boolean value, rather than string,


try setting up the business rule like this and test if that works as expected in your case:



Condition:


current.caller_id.u_cs_home_agent == true && current.watch_list.indexOf(current.caller_id.manager) == -1  




Script:


(function executeRule(current, previous /*null when async*/) {  


// Add your code here  


if (current.watch_list == ''){  


      current.watch_list += current.caller_id.manager;  


      } else {  


      current.watch_list += ',' + current.caller_id.manager;  


      }  


      })(current, previous);



Please let me know if this solves your issue.



Best regards,


A.


View solution in original post

4 REPLIES 4

Andras Kisgyorg
Kilo Guru

HI Andrea,



It should be a before update business rule, and you can leave the condition in place but remove the apostrophes from "true" check as it validates the boolean value, rather than string,


try setting up the business rule like this and test if that works as expected in your case:



Condition:


current.caller_id.u_cs_home_agent == true && current.watch_list.indexOf(current.caller_id.manager) == -1  




Script:


(function executeRule(current, previous /*null when async*/) {  


// Add your code here  


if (current.watch_list == ''){  


      current.watch_list += current.caller_id.manager;  


      } else {  


      current.watch_list += ',' + current.caller_id.manager;  


      }  


      })(current, previous);



Please let me know if this solves your issue.



Best regards,


A.


Hello Andras,



Thank you so much for the quick reply.   It's working...:)))


HI Andrea,



In the meantime I realized that some more scripting and conditions needs to be added to your business rule to ensure it works and adds caller manager to the watch list properly, especially if the incident is getting updated multiple times.



You should use the updated business rule below:



Condition:


current.caller_id.u_cs_home_agent == true && current.watch_list.indexOf(current.caller_id.manager) == -1



Script:


(function executeRule(current, previous /*null when async*/) {



      // Add your code here


if (current.watch_list == ''){


      current.watch_list += current.caller_id.manager;


      } else {


      current.watch_list += ',' + current.caller_id.manager;


      }


})(current, previous);




Best regards,


A.


Hello Andras,



I've changed the business rule and everything works great...Thanks again..:)