
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 08:02 AM
I am working on a notification to go out to users who have records in a table. I am able to make it so they get one email with a listing of all the records they have instead of individual. I was only able to get it to show like this.
Number: TISU0001, State: Work In Progress, etc.
This is one per line. How can I change my mail script so that it comes to them in a table format like below.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 08:51 AM
This sounds very similar to what I have. My guess is that you want some way of capturing those records, then iterating through them. Here is what I have for KB articles:
function checkRevDate() {
var aDt = new GlideDateTime();
aDt.addDays(7);
var cDate = aDt.toString().split(' ')[0];
var kb = new GlideRecord('kb_knowledge');
kb.addQuery('workflow_state', '!=', 'retired');
kb.addQuery('author', '!=', '');
kb.addQuery('valid_to', '<=', cDate);
kb.query();
kbArray = [];
while (kb.next()) {
kbArray.push(kb.author.toString());
}
var arrUtil = new global.ArrayUtil();
var uKbArray = arrUtil.unique(kbArray);
for (k = 0; k < uKbArray.length; k++) {
var kno = new GlideRecord('kb_knowledge');
kno.addQuery('workflow_state', '!=', 'retired');
kno.addQuery('author', '!=', '');
kno.addQuery('author', uKbArray[k]);
kno.addQuery('valid_to', '<=', cDate);
kno.orderBy('author');
kno.query();
var kbID = [];
kbCount = 0;
while (kno.next()) {
kbID.push(kno.sys_id.toString());
kbCount++;
if (kbCount == kno.getRowCount()) {
gs.eventQueue('kb_knowledge.review', kno, uKbArray[k], kbID);
}
}
}
}
This will capture an array of sys_id for each author found. Then, in my notification email script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
template.print("<table>");
template.print("<tr><th align='left'>Number</th><th align='left'>Short Description</th><th align='left'>Valid to date</th></tr>");
var kbRec = new GlideRecord('kb_knowledge');
var sKbRec = event.parm2.split(',');
var tbl = current.getTableName();
for (x = 0; x < sKbRec.length; x++) {
kbRec.get(sKbRec[x]);
var link = createLinkForObject(tbl,kbRec.sys_id,kbRec.number);
template.print("<tr><td>" + link + "</td><td>" + kbRec.short_description + "</td><td>" + kbRec.valid_to + "</td></tr>");
}
template.print("</table>");
})(current, template, email, email_action, event);
function createLinkForObject(strTableName, strSysID, strLabel) {
return '<a href="' + gs.getProperty('glide.servlet.uri') + 'nav_to.do?uri=' + gs.generateURL(strTableName, strSysID) + '">' + strLabel + '</a>';
}
This builds a table for each of the given columns needed. I get each of the records based upon the array of sys_id passed as a parameter built from the scheduled job. Then, I put in all of the details from each record I got. As an added feature, I also build a link for each record so the user can click on the link and get into the record.
Feel free to pull from this method and use with your own table (since it appears to be a custom table).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 08:10 AM
Can you please share the mail script.
You can use HTML tags to format table.
Thanks
Shashikant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 08:14 AM
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
template.print("Please provide and updates on the below issue(s). \n");
var gr = new GlideRecord ("u_issue_tracker");
gr.addQuery('u_owner', current.u_owner);
gr.addQuery('u_active', true);
gr.query();
while (gr.next()){
template.print("Issue Number: " + gr.u_issue_number + ", Action Item: "+ gr.u_acation_item + ", Severity Rating: " + gr.u_severity_rating +
", Description: " + gr.u_description + "\n");
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 08:32 AM
Can you try below code:
template.print('<table style="width:100%">');
var gr = new GlideRecord ("u_issue_tracker");
gr.addQuery('u_owner', current.u_owner);
gr.addQuery('u_active', true);
gr.query();
while (gr.next()){
template.print('<tr><th>Issue Number:</th><th>Action Item:</th><th>Severity Rating:</th><th>Description: </th></tr>');
template.print('<tr><td>'+ gr.u_issue_number +'</td><td>' + gr.u_acation_item + '</td><td>' + gr.u_severity_rating +'</td><td>' + gr.u_description +'</td></tr>');
}
template.print('</table>');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 08:34 AM