
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 04:13 AM
Hi,
As my scripting abilities are somewhat lacking, I have a scenario where I need to email the user defined by a catalog variable, call it user_affected, after the task has been completed. In the workflow, I have added the notification tile, and tried the following in the advanced script:
// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.
answer = [];
var user = current.variables.user_affected;
answer.user;
Unsurprisingly, it didnt generate an email to the answer for user_affected. Where am I going wrong please. Note the user_affected would be a record on sys_user table with a valid email address.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 04:31 AM
Hi
So its a little difficult to guess what's the issue with only a fraction of the setup, but the correct way to add something to an array like answer, is:
//This is not correct
//awswer.user;
answer.push('some@email.com');
Also the user_affected is probably a GlideRecord? So you would need something like current.variables.user_affected.email to get the email address.
answer.push(current.variables.affected_user.email);
Hope it makes sense 🙂
-Mark

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 04:31 AM
Hi
So its a little difficult to guess what's the issue with only a fraction of the setup, but the correct way to add something to an array like answer, is:
//This is not correct
//awswer.user;
answer.push('some@email.com');
Also the user_affected is probably a GlideRecord? So you would need something like current.variables.user_affected.email to get the email address.
answer.push(current.variables.affected_user.email);
Hope it makes sense 🙂
-Mark

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 04:54 AM
Thanks Mark,
Changed my code to this and it works as required
answer = [];
var user = current.variables.user_affected;
answer.push(current.variables.user_affected.email);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 05:00 AM
Awesome! Glad to hear! 🙂
Unless you need the user variable somewhere else, you can just delete that line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 04:43 AM
Hi,
Try below,
answer = [];
answer=current.variables.user_affected;
answer;
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP