I am passing some email ids through event param2, and I want to add some more email ids in CC.. is it possible?

Sathwik1
Tera Expert

I am passing some email ids through event param2, and I want to add some more email ids in CC.. is it possible?

1 ACCEPTED SOLUTION

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

View solution in original post

22 REPLIES 22

You can just pass 'obj' from your script and use it as I mentioned above.


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

Thanks for your help @Rohila Voona 

Some how that wasn't working.. so I changed my logic and trying to get cc mails from email script.. that was working fine..values are getting..

but here issue is..

In schedule job I am passing the below parameters.

   gs.eventQueue('x_408194_loading_e.incident.over30days', gr, getEmail[i], incidents.toString());

 

In event2 param.. it stores sysid of the records, so those values are directly getting into the event logs... why it was happening like that? any issue in my email script? providing email script below..

please help me on this.. about to achieve my requirement. Only this part is pending @Rohila Voona 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var getRec = event.parm2.toString();
	gs.info("Get Total Records "+getRec);
    var gr = new GlideRecord('x_408194_loading_e_scoped_data_table');
    gr.addEncodedQuery('sys_idIN' + getRec);
    gr.query();
    while (gr.next()) {
        var gr2 = gr.id2;
        gs.info("Single CC Users" + gr2);
        var gr3 = new GlideRecord('sys_user');
        gr3.addEncodedQuery('user_nameIN'+gr2);
        gr3.query();
        if (gr3.next()) {
			var getEm = gr3.email;
			var getNm = gr3.name;
            email.addAddress("cc", getNm.toString(), getEm.toString());
            template.print(gr.name);
            template.print('\n');
            template.print('\n');
        }
    }

})(current, template, email, email_action, event);

You changed the complete requirement of how to pass all the values from event paramter.

 

what's the log value you are getting here.

	gs.info("Get Total Records "+getRec);

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