BCC email notification from parm1

Moedeb
Tera Guru

I am wanting to send a notification out to a changing list of recipients, I already have that handled in a flow that ultimately fires an event that contains the recipient list, however it is adding those from parm1 into the 'To' field of the notification and I'd like it to not add anyone to the 'To' field and instead add them to the 'BCC'

 

I know that if I have a set list I can add the users via a mail script, however I'm not aware of how to handle it when I want to use parm1 instead of a particular user.

 

Anyone able to assist please?

11 REPLIES 11

Gangadhar Ravi
Giga Sage
Giga Sage

@Moedeb you need to use email script for this. Please refer below example 

 

// Get the recipients list from parm1
var recipients = event.parm1; 

if (recipients) {
    // Convert parm1 to an array (in case it's comma-separated)
    var recipientArray = recipients.split(',');

    // Add each recipient to the BCC list
    for (var i = 0; i < recipientArray.length; i++) {
        email.addAddress("bcc", recipientArray[i].trim());
    }
}

And in email notification body you need to call email script. below is syntax.

 

${mail_script:scriptName}

 

Please mark my answer correct and helpful if this works for you.

 

@Gangadhar Ravi so that sort of worked - it sends to the recipient list as a BCC, but the notification is also sent to the to list, so it is ultimately generating 2 notifications for each person.

 

I tried unselecting 'event parm 1' from the Who will receive on the notification, then it didn't send to anyone at all.

Amit Verma
Kilo Patron
Kilo Patron

Hi @Moedeb 

 

You can refer below post to get the logic :

https://www.servicenow.com/community/developer-forum/adding-email-addresses-from-event-parm1-to-bcc-...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello,

 

To handle a situation where you want to send a notification to a dynamic list of recipients using a parm1 parameter but place all recipients in the BCC field rather than the "To" field, you will need to customize the notification script to manipulate the email headers accordingly. Here’s how you can approach this in a script:

  1. Create or Update the Notification Script: You need to use a script to customize the behavior of your notification. Since you want to use parm1 for the recipient list and place all of them in the BCC field, you’ll need to modify the notification’s email sending logic.

  2. Sample Script for Notification: Below is a sample script that shows how you might achieve this in a notification script. This script assumes that parm1 contains a comma-separated list of email addresses.

     
    // Notification script
    (function sendNotification() { var recipients = current.event.parm1; // Retrieve recipient list from parm1 // Ensure recipients are in a format we can use var recipientList = recipients.split(','); // Split by comma to handle multiple recipients // Create email message object var mail = new GlideEmailOutbound(); // Set email subject and body mail.setSubject('Your Notification Subject'); mail.setBody('Your Notification Body'); // Set BCC field mail.setBcc(recipients); // Send email mail.send(); })();
    • Explanation:
      • current.event.parm1 retrieves the dynamic recipient list.
      • recipients.split(',') splits the comma-separated list into an array of email addresses.
      • mail.setBcc(recipients) sets all addresses to the BCC field.
      • mail.send() sends the email

Regards,

Vaishnavi Lathkar