Email to be sent to all users in list collector variable along with Requested For and Submitted By

kbanerje
Mega Guru

Hi All,

I have a record producer that creates a Facility Request.While filling the form we have a list collector variable as "Email CC" as below image.

Requirement is which ever user name/s is/are selected from Available to Selected and then Submitting the form it should sent an email to notification to the caller ,open_by(already implemented by adding them in the Users/group field in notification under "Whom to send" section) and all users selected in   "Selected" slush bucket of the variable Email CC(email_cc).

Below is the email template script we are using and referencing the same in the email notification.

Please advice the change required to achieve the same.

Capture.PNG

Email Template Script:

<mail_script>

//Retrieve the current requester sys_id

var recipient =   event.parm1;

// Impersonate recipient in order to obtain automatically the language information for

// the execution of the script and use the auto-translation feature

var v_sCurrentLoggedInUser = gs.getUserID();

var impersonator = gs.getSession().impersonate(recipient);

// Set email From

email.setFrom("The Iris Team [do not reply]");

// Set opened by user in CC

if(current.request.requested_for != current.request.opened_by) {

                  email.addAddress("cc", current.request.opened_by.email, current.request.opened_by.getDisplayValue());

}

// Set the subject

  var subject = gs.getMessage("New Facilities Request" + ":" +current.number.getDisplayValue() + " is Opened.");    

  email.setSubject(subject);

</mail_script>

<mail_script>

var checkMarkURL = 'https://' + gs.getProperty('instance_name') + '.service-now.com/checkmark_green_20px.png';

var FcrUrL = 'https://' + gs.getProperty('instance_name') + '.service-now.com/nav_to.do?uri=facilities_request.do?sys_id='+current.sys_id;

//var takeSurveyURL = event.parm2;

// Check if recipient user as role ITIL or ITIL_ADMIN

/*

if(ifUsrITIL(event.parm1))     {

    requestURL   =   'https://' + gs.getProperty('instance_name') + '.service-now.com/com.glideapp.servicecatalog_checkout_view.do?sysparm_sys_id=' + current.sys_id;      

}

*/

  var v_htmlHeaderFooter = new EmailTemplateUtil();

  var v_htmlFooter = v_htmlHeaderFooter.generateFooter(gs.getMessage('Thank you'), gs.getMessage('The IRIS Team'), gs.getMessage('Questions?'), gs.getMessage('We can'), gs.getMessage('help'));

  template.print(v_htmlHeaderFooter.generateHeader());

</mail_script>

<div style="margin: 30px 30px 0; font: 12px/14px Helvetica; color: #424242;"><mail_script>template.print(gs.getMessage('Hello'))</mail_script> <mail_script>template.print(current.caller.first_name)</mail_script>,</div>

<div style="margin: 30px 30px 0; "><h3 style=" margin: 0; padding: 0; font: bold 28px/30px Helvetica; color: #82A0DB;"><mail_script>template.print(gs.getMessage('New Facilities Request is created.'))</mail_script></h3></div>

<!--<table border="0" style="margin: 0px 50pt; width: 550pt; border-radius: 10px; font: 12px/14px Helvetica; color: #424242;">

  <tr><td colspan="4" style="text-align: center; padding: 20px 30px 30px;"><table style='border: 1px solid #424242; background: #82A0DB;'><tbody><tr><td><mail_script>template.print("<a href='" + takeSurveyURL+ "'" + " style='display:inline-block; color:#fff; padding: 7px 12px; text-decoration:none; font:bold 12px/14px Helvetica; border:1px solid #82A0DB'>" + gs.getMessage('TAKE THE SURVEY') + "</a>")</mail_script></td></tr></tbody></table></td>

  </tr>

</table> -->

<table border="0" style="background: #F8FAF9; margin: 0px 50pt 0px 50pt; width: 550pt; border-radius: 10px; font: 12px/14px Helvetica; color: #424242;">

<tr>

  <td   style="padding: 20px 10px 0 30px; "><b><mail_script>template.print(gs.getMessage('Caller:'))</mail_script></b></td>

  <td colspan="3" style="padding: 20px 30px 0;"><mail_script>template.print(current.caller.first_name + " " +current.caller.last_name)</mail_script></td>

</tr>

<tr>

  <td   style="padding: 20px 10px 0 30px;" ><b><mail_script>template.print(gs.getMessage('Facility Request #:'))</mail_script></b></td>

  <td colspan="3" style="padding: 20px 30px 0;"><a href="" style=" color: #82A0DB; text-decoration: underline; "><mail_script>template.print('<a href=\" ' + FcrUrL+ '\"     style=" color: #82A0DB; text-decoration: underline; ">'+"     " + current.number.getDisplayValue()+'</a>');</mail_script></a></td>

</tr>

<tr>

  <td   style="padding: 20px 10px 0 30px;" ><b><mail_script>template.print(gs.getMessage('Short Description'))</mail_script></b></td>

  <td colspan="3" style="padding: 20px 30px 0;"><mail_script>template.print(current.short_description);</mail_script></a></td>

</tr>

<tr>

  <td style="padding: 20px 10px 0 30px;"><b><mail_script>template.print(gs.getMessage('Submitted by:'))</mail_script></b></td>

  <td style="padding: 20px 30px 0;"><mail_script>template.print(current.opened_by.first_name)</mail_script> <mail_script>template.print(current.opened_by.last_name)</mail_script></td>

  <td style="padding: 20px 0 0;"><b><mail_script>template.print(gs.getMessage('On:'))</mail_script></b></td>

  <td style="padding: 20px 30px 0 0;"><mail_script>template.print(current.opened_at.getDisplayValue() + " EST")</mail_script></td>

</tr>

<!--<tr><td   colspan="4" style="padding: 20px 10px 0 30px;" ></td></tr>-->

</table>

<mail_script>

  template.print(v_htmlFooter);

</mail_script>

<mail_script>gs.getSession().impersonate(v_sCurrentLoggedInUser);</mail_script>

ctomasi

1 ACCEPTED SOLUTION

Hi Kirtiman,



Due to the level of detail you posted, I had assumed that you had written the original script and would be able to patch in a few more lines of code based on my description. Apologies.



Your solution is going to look something like this. Keep in mind, this code is untested and likely will not work by copying & pasting. It is meant as a starting point and you are expected to work with it to get it running.



Right after you add the opened_by address in the mail script, do something like this:



var cc = current.variables.email_cc.split(',');



for (var i = 0; i < cc.length; i++) {


        var u = new GlideRecord('sys_user');


        if (u.get(cc[i])) {


                  email.addAddress("cc", u.email, u.getDisplayValue());


        }


}


View solution in original post

3 REPLIES 3

Chuck Tomasi
Tera Patron

I see in your email script where you are adding the opened_by to the cc using email.addAddress(), but I don't see anywhere else where you are referencing the current.variables.email_cc. You'll need to split the list of sys_ids in that variable and loop through them to include the email addresses of the corresponding sys_user record one by one.


Hi Chuck,



I am not familiar with this before can you help me with a snippet,please?



Also what do I have to add in the Whom to send part of the notification.



Kind Regards,


Kirtiman


Hi Kirtiman,



Due to the level of detail you posted, I had assumed that you had written the original script and would be able to patch in a few more lines of code based on my description. Apologies.



Your solution is going to look something like this. Keep in mind, this code is untested and likely will not work by copying & pasting. It is meant as a starting point and you are expected to work with it to get it running.



Right after you add the opened_by address in the mail script, do something like this:



var cc = current.variables.email_cc.split(',');



for (var i = 0; i < cc.length; i++) {


        var u = new GlideRecord('sys_user');


        if (u.get(cc[i])) {


                  email.addAddress("cc", u.email, u.getDisplayValue());


        }


}