- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 08:15 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 05:36 AM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:00 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 10:48 PM
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.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 01:26 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 05:25 AM
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
Regards,
Abhijit
ServiceNow MVP