How to get recipient list populated in to 'TO' section of email client template

riddhi wasurkar
Tera Contributor

Hello 

We've developed a UI action called 'Compose.' Clicking on it displays an email client template body. Currently, our script populates recipients, but with a large number of recipients, we're experiencing a delay of about 2-3 minutes due to a 'While loop.' Are there any alternative solutions for this issue?

 

Please find below scripts:

Script Include:

 

getRecip: function() {
        var users = [];
        var tbName = this.getParameter('sysparm_id'); // Calling sysparam_id from Ui page (this will be sys_id of record)
        var gr2 = new GlideRecord('comm_task');
        gr2.addQuery('sys_id', tbName);
        gr2.query();
        if (gr2.next()) {
            var modelgetRecip = this.getParameter('sysparm_modelsys_id');
            var gr = new GlideRecord('sn_publications_recipients_list');
            gr.addQuery("sys_id", modelgetRecip);
            gr.query();
            if (gr.next()) {
                var gr1 = new GlideRecord('sn_publications_recipientslist_user_m2m');
                gr1.addQuery("recipients_list", gr.sys_id);
                gr1.query();
                while (gr1.next()) {   //We are causing an delay here due to more number of records
                    var userEmail = gr1.user.toString();
                    users.push(userEmail);
                }
            }
            gr2.u_recipients_list_values = users.join(',');
            gr2.update();
        }
        return 'sys_idIN' + users.join(",");
    },
 
riddhiwasurkar_0-1704100307979.png

 

riddhiwasurkar_1-1704100356628.png

 

 

Any help resolving the issue would be greatly appreciated.
Thank You

 

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi @riddhi wasurkar 

I'm wondering about your delay of 2-3 minutes. Therefore my question: How many users are we talking about here? 

Please be aware of restrictions regarding the number of possible recipients in the fields TO, CC & BCC. You cannot add thousands of email addresses there! That's the reason why the feature "Targeted Communications" (you are reading the recipients from its table!) works differently.

Maik


Hello @Maik Skoddow ,

Thank you for the response.

Our recipient list contains 20,000+ users records and we are trying to populate these users into the 'TO' section of the email client template. While populating these users into the 'TO' section it is taking 2-3 minutes.

If you have any document related to restrictions of recipients list, then please provide.


 

Hi @riddhi wasurkar 

I couldn't find so fast any suitable RfC but most of the Email Clients restrict maximum number of addresses to something like 500 (Outlook for example).

ServiceNow has a restriction of 1000 (see https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0748535 )

20.000 email addresses is definitely too much and will be rejected from any email server!

Have you also thought about what a security breach you are committing if thousands of e-mail recipients can see the e-mail addresses of thousands of other users?

Again: There is a reason why ServiceNow introduced the "Targeted Communications" feature. So use it as intended and you will have no problems, as ServiceNow will create individual emails for each and every recipient.

Maik

Maik

Hello @Maik Skoddow ,
Thank you the response!

In the Communication task table i have created Email client configuration  i.e 'Communication Task - Email Client Configuration' using this now Recipient list name is populated in 'TO' section of email client template. But, when I received an email recipients field is displayed empty. 


Please find the below screenshots:


1. email client configuration:

riddhiwasurkar_3-1704189618979.png

 

2. email client template:

riddhiwasurkar_2-1704189566883.png


3. email 

riddhiwasurkar_4-1704189726191.png

 


Is this functionality only works for the Incident alert task table or we can use another table also for the same. For e.g 'Communication task' table

 

Any help resolving the issue would be greatly appreciated.
Thank You