need to attach my queried records from a table as excel attachment in email triggered from an event.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2024 06:58 AM
i already query indicator task table and filter incomplete records using an email script and the records are mentioned in the email as a table. I want the same queried records be attached as an excel file in the same email that is triggered using an event. How to do ?
The email script is mentioned below.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var profiles = [];
var func = [];
var sfun = [];
var conr = [];
var ids = event.parm2;
//get all pending tasks
var gr = new GlideRecord('sn_grc_indicator_task');
gr.addQuery('sys_id', 'IN', ids);
gr.query();
while (gr.next()) {
profiles.push(gr.indicator.item.profile.name.toString());
func.push(gr.indicator.item.type.name.toString());
sfun.push(gr.indicator.item.u_sub_function.toString());
conr.push(gr.indicator.item.owner.name.toString());
}
//consider unique profiles and functions
var unique_array = new ArrayUtil();
var pf = unique_array.unique(profiles);
gs.print(pf);
var fn = unique_array.unique(func);
gs.print(fn);
var sf = unique_array.unique(sfun);
gs.print(sf);
var onr = unique_array.unique(conr);
gs.print(onr);
//create table for combination of profiles and functions and count of each combination
template.print('<table border="1"><tr><td>Profile</td><td>Function</td><td>Sub Function</td><td>#Pending Indicators</td></tr>');
for (var i = 0; i < pf.length; i++) {
for (var j = 0; j < fn.length; j++) {
for (var k = 0; k < sf.length; k++) {
for (var l = 0; l < onr.length; l++) {
var rec = new GlideRecord('sn_grc_indicator_task');
rec.addEncodedQuery('sys_idIN' + ids + '^indicator.item.profile.name=' + pf[i] + '^indicator.item.type.name=' + fn[j] + '^indicator.item.owner.name=' + onr[l] + '^indicator.item.u_sub_function=' + sf[k]);
rec.query();
var count = rec.getRowCount();
if (count) {
template.print('<tr><td>' + pf[i] + '</td><td>' + fn[j] + '</td><td>' + sf[k] + '</td><td>' + count + '</td></tr>');
}
}
}
}
}
template.print('</table>');
})(current, template, email, email_action, event);
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2024 12:07 AM
Hi @Ravivarman Saee ,
I'm sure that it won't work, I'd suggest you to try it with events, business rules, and script actions.
Regards, Ivan