Why is the notification not sending to cc the emails?

Community Alums
Not applicable

Hiii ! 
I made this little script in the Email Script:

(function runMailScript(current, template, email, email_action, event) {


    var gr = new GlideRecord("test");
    var encodedQuery = gs.getProperty("x_encodedQuery");
    gr.addEncodedQuery(encodedQuery);
    gr.query();

    while (gr.next()) {
        email.addAddress("cc", gr.pu_user.email, gr.pu_user.getDisplayValue());
    }

but it is not working for me. When I do the preview in the notification it doesn't show me any of the emails, it's all blank. I only did this email script and in the template part of the notification I put the name of the template, but nothing else. Could it be that I missed something? Thank you very much.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

I've seen this and your other post and so this circles back to a "To" recipient.

If you're wanting these users to be listed as the "To" and to ensure this notification goes out, you'd want to create an event, then trigger the event, which you'd then set your notification to fire upon event trigger.

https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/platform-events/task...

So you would make this decision in a business rule or somewhere else and give the list of recipients to your event to pass to the notification. In the "who to send to" tab, you would check (for example): parm1 contains recipients as well as send to event creator.

Your event script could look like:

var userArray = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('company', 'sys_id_here');
gr.addQuery('vip', true);
gr.query();
while (gr.next()) {
userArray.push(gr.sys_id);
}
if (userArray.length > 0) {
gs.eventQueue('name_of_event', current, userArray.toString(), '');
}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

8 REPLIES 8

Allen Andreas
Administrator
Administrator

Hi,

I've seen this and your other post and so this circles back to a "To" recipient.

If you're wanting these users to be listed as the "To" and to ensure this notification goes out, you'd want to create an event, then trigger the event, which you'd then set your notification to fire upon event trigger.

https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/platform-events/task...

So you would make this decision in a business rule or somewhere else and give the list of recipients to your event to pass to the notification. In the "who to send to" tab, you would check (for example): parm1 contains recipients as well as send to event creator.

Your event script could look like:

var userArray = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('company', 'sys_id_here');
gr.addQuery('vip', true);
gr.query();
while (gr.next()) {
userArray.push(gr.sys_id);
}
if (userArray.length > 0) {
gs.eventQueue('name_of_event', current, userArray.toString(), '');
}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Community Alums
Not applicable

Hi Allen! Yes, I also thought of this solution as a plan B. I think it's a good solution, but I tried to bring the emails through the email script since this brought me everything in one and I could send a single notification with all the emails. On the other hand, if I do it through an event, I have to send one notification for each email, it would not be a good performance. I think I'm going to go for this solution, since I think have no other option. Thank you very much for your answer, it is very helpful!

Hello,

My solution has you only sending one notification...with all the users on it as a recipient.

I don't think you understood my solution or your reply was mistyped to me.

My solution does not result in 30+ emails...it's 1 email with all the users on it as recipients.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Community Alums
Not applicable

Yes, you're right! Your solution sends everything at once. I misunderstood it with another solution, sorry. I'm going to go with this one, it's a great help. Thank you very much! 🙂