- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 04:16 AM
I am passing some email ids through event param2, and I want to add some more email ids in CC.. is it possible?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 11:08 PM
Ok Got it,
Since we cannot set TO address from script, pass these values as param1 (modify notification to include param1 as recipents)
For parameter2, try this
create a json and pass incidents,cc address values.
var assigneeArr = [];
var assigneeArrr=[];
var incidentArr = [];
var getEmail = [];
var gr = new GlideRecord("x_408194_loading_e_scoped_data_table");
gr.query();
while (gr.next()) {
incidentArr.push(gr.sys_id.toString());
assigneeArr.push(gr.id.toString());
assigneeArrr.push(gr.id2.toString());
}
var uniqueAssignees = new global.ArrayUtil().unique(assigneeArr);
var uniqueAssigneees = new global.ArrayUtil().unique(assigneeArrr);
gs.info("Unique TO Users " +uniqueAssignees);
gs.info("Unique CC Users " +uniqueAssigneees);
for (var i = 0; i < uniqueAssignees.length; i++) {
var incidents = [];
for (var j = 0; j < assigneeArr.length; j++) {
if (uniqueAssignees[i] == assigneeArr[j]) {
var gr2 = new GlideRecord('sys_user');
gr2.addQuery('user_name', assigneeArr[j]);
gr2.query();
if (gr2.next()) {
getEmail.push(gr2.email);
}
incidents.push(incidentArr[j]);
}
}
var cc=[];
for ( i = 0; i < uniqueAssigneees.length; i++) {
for ( j = 0; j < assigneeArrr.length; j++) {
if (uniqueAssigneees[i] == assigneeArrr[j]) {
var gr3 = new GlideRecord('sys_user');
gr3.addQuery('user_name', assigneeArrr[j]);
gr3.query();
if (gr3.next()) {
cc.push(gr3.email);
}
}
}
var obj={};
obj['incidents'] = incidents.toString();
obj['cc'] = cc.toString();
gs.info("Get All Email Id's " +getEmail[i]);
gs.eventQueue('x_408194_loading_e.incident.over30days', gr, getEmail, obj);
}
}
In email-script access param2
var cc = event.param2.cc;
var inc = event.param2.incidents
param1 will have TO address, param2 will have both cc and incidents info.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 05:44 AM
Hi sathwik
yes you can pass the values from parameter and add those users in cc
email.addAdddress("cc",event.param2);
if this is nit what you are looking for then provide more details on how you are passing param2 values.
Example scripting for email notifications
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 06:00 AM
Hi, from schedule script..
in event parm2 I am already passing some mail ids.. along with that I need to some more mail id;s but those needs to send mail in CC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 06:28 AM
Hi sathwik
you can concat it in param2 with a seperator(maybe # or %...) and split it in your email_script.
var cc = event.param2.toString().split("#");
can you share scheduled job logic.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2022 09:52 AM
var assigneeArr = [];
var incidentArr = [];
var getEmail = [];
var gr = new GlideRecord("x_408194_loading_e_scoped_data_table");
gr.query();
while (gr.next()) {
incidentArr.push(gr.sys_id.toString());
assigneeArr.push(gr.id.toString());
}
var uniqueAssignees = new global.ArrayUtil().unique(assigneeArr);
for (var i = 0; i < uniqueAssignees.length; i++) {
var incidents = [];
for (var j = 0; j < assigneeArr.length; j++) {
if (uniqueAssignees[i] == assigneeArr[j]) {
var gr2 = new GlideRecord('sys_user');
gr2.addQuery('user_name', assigneeArr[j]);
gr2.query();
if (gr2.next()) {
getEmail.push(gr2.email);
}
incidents.push(incidentArr[j]);
}
}
gs.eventQueue('x_408194_loading_e.incident.over30days', gr, incidents.toString(), getEmail[i]);
}
Email Script
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var gr = new GlideRecord("x_408194_loading_e_scoped_data_table");
gr.addEncodedQuery("sys_idIN" + event.parm1.toString());
gr.query();
while (gr.next()) {
var getCCId = gr.id2;
var getEmail = new GlideRecord('sys_user');
getEmail.addQuery('user_name', getEmail);
getEmail.query();
if (getEmail.next()) {
email.addAddress("cc", getEmail.name, getEmail.email);
template.print(getEmail.name);
template.print(gr.number);
template.print('\n');
template.print('\n');
} }
})(current, template, email, email_action, event);
In email script, I have written email.address, those needs to pass in event parm2