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

Hi Abhijit ,

Thanks for responding,

this script is not working not updating the list field and its a scoped application do we missing anything .Any other suggestions.

It doesn't matter if its scope or global app. Try adding infomessage inside if conditions to check if it going inside condition properly.

Also please share your updated script so that we can help you further.

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

hi abhijit ,

I tried with removing after the && conditon then its working fine but creating duplicates.

In info1 on form its showing as false .

&& current.users_who_worked_the_case.toString().indexOf(inas)==-1){
if (current.u_initial_assigned_to_ris.changes()) {
        if (current.users_who_worked_the_case) {
            gs.addErrorMessage('info1' + current.users_who_worked_the_case.toString().indexOf(assign_to)==-1);
            current.users_who_worked_the_case += "," + inas;
        } else {
            current.users_who_worked_the_case = inas;
        }

The condition that you have added in info message is for 'assign_to', you should be adding it for 'inas' variable

Replace below info message:

gs.addErrorMessage('info1' + current.users_who_worked_the_case.toString().indexOf(assign_to)==-1);

with below message 

gs.addErrorMessage('info1' + current.users_who_worked_the_case.toString().indexOf(inas)==-1);

Now it should work and message should print as true.

Let me know if you have any further queries.

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