Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

kamadi lokeshra
Tera Contributor

Hi,

Solution to the  email of the user defined by a catalog variable after the task has been completed.

In the workflow add in the script:

// Set the variable 'answer' to a comma-separated list of user or group sys_ids that you want the email sent to.
answer = [];
answer.push(current.variables.variable name.sys_id);
answer.push(current.variables.variable name.sys_id);

 

Note: Here variable name is a reference field.

Please mark this as Correct or Helpful if it helps.

 

Thanks and Regards,

Lokesh