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

List field Update

thirumala2
Tera Guru

Hi ,

I have a requirement where there is a  field of type list (Users Who Worked the Case)referenced to sys_user table .

There are 3 other fields refernced to sys_user table :Initial Assigned to,Assigned to ,# of Outreach Attempts Needed to Resolve

Whenever the Initial Assigned to changes

           -  IF the Initial Assigned to user is not already in the "Users Who Worked the Case" list field, then automatically add the Initial Assigned to user to the list.

Whenever the Assigned to changes

           -  IF the Assigned to user is not already in the "Users Who Worked the Case" list field, then automatically add the Assigned to user to the list.

 Whenever an agent changes the "# of Outreach Attempts Needed to Resolve" dropdown value:

           -  IF the current user is not already in the "Users Who Worked the Case" list field, then automatically add the Assigned to user to the list.

kindly help me with the solution.

 

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi, 

Try below script,

BR Condition : Initial Assigned to changes OR Assigned to changes OR Outreach Attempts Needed to Resolve changes

Script :

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

    // Add your code here
    var inas = current.u_initial_assigned_to_ris;
    var assign_to = current.assigned_to;
    var outreach = gs.getUserID();
    var users = current.users_who_worked_the_case.split(',');
  
if(current.u_initial_assigned_to_ris.changes() && current.users_who_worked_the_case.toString().indexOf(inas)==-1){
      if(current.users_who_worked_the_case){
current.users_who_worked_the_case+=","+inas;
}else{
current.users_who_worked_the_case=inas;
}
}
if(current.assigned_to.changes() && current.users_who_worked_the_case.toString().indexOf(assign_to)==-1){
      if(current.users_who_worked_the_case){
current.users_who_worked_the_case+=","+assign_to ;
}else{
current.users_who_worked_the_case=assign_to ;
}
}
if(current.outreach_needed_to_resolve.changes() && current.users_who_worked_the_case.toString().indexOf(outreach)==-1){// change field name 'outreach_needed_to_resolve' with actual field name
      if(current.users_who_worked_the_case){
current.users_who_worked_the_case+=","+outreach;
}else{
current.users_who_worked_the_case=outreach;
}
}
   

})(current, previous);

Please mark this as Correct or Helpful if it helps.

Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

8 REPLIES 8

Allen Andreas
Administrator
Administrator

Hello,

Please share more from your side such as what you've done, what you've tried, etc.

So far, you've only posted your requirement with nothing else from your side.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

hi ,

I have tried before insert,update business rule with below script :

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

    // Add your code here
    var inas = current.getDisplayValue('u_initial_assigned_to_ris');
    var assign_to = current.getDisplayValue('assigned_to');
    var outreach = gs.getUserID();
	var users = current.users_who_worked_the_case.split(',');

    if (current.inas != users) {
        
        users.push(current.u_initial_assigned_to_ris.toString());
        users = new ArrayUtil().unique(users);
        current.users_who_worked_the_case = users.toString();
    } else if (current.assign_to != users) {
       // var users = current.users_who_worked_the_case.split(',');
        users.push(current.assign_to.toString());
        users = new ArrayUtil().unique(users);
        current.users_who_worked_the_case = users.toString();
    }

})(current, previous);

@asifnoor @Justin Abbott @shloke04 

Abhijit4
Mega Sage

Hi, 

Try below script,

BR Condition : Initial Assigned to changes OR Assigned to changes OR Outreach Attempts Needed to Resolve changes

Script :

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

    // Add your code here
    var inas = current.u_initial_assigned_to_ris;
    var assign_to = current.assigned_to;
    var outreach = gs.getUserID();
    var users = current.users_who_worked_the_case.split(',');
  
if(current.u_initial_assigned_to_ris.changes() && current.users_who_worked_the_case.toString().indexOf(inas)==-1){
      if(current.users_who_worked_the_case){
current.users_who_worked_the_case+=","+inas;
}else{
current.users_who_worked_the_case=inas;
}
}
if(current.assigned_to.changes() && current.users_who_worked_the_case.toString().indexOf(assign_to)==-1){
      if(current.users_who_worked_the_case){
current.users_who_worked_the_case+=","+assign_to ;
}else{
current.users_who_worked_the_case=assign_to ;
}
}
if(current.outreach_needed_to_resolve.changes() && current.users_who_worked_the_case.toString().indexOf(outreach)==-1){// change field name 'outreach_needed_to_resolve' with actual field name
      if(current.users_who_worked_the_case){
current.users_who_worked_the_case+=","+outreach;
}else{
current.users_who_worked_the_case=outreach;
}
}
   

})(current, previous);

Please mark this as Correct or Helpful if it helps.

Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP