Set email recipient based on variable answer

Cirrus
Kilo Sage

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

1 ACCEPTED SOLUTION

Mark Guldhammer
Giga Guru

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

View solution in original post

5 REPLIES 5

Mark Guldhammer
Giga Guru

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

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);

Awesome! Glad to hear! 🙂

Unless you need the user variable somewhere else, you can just delete that line.

Abhijit4
Mega Sage

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

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