- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 12:35 AM
Hi All,
The requirement is to show the below content in tabular format in notification-
Mobile Request
Submitted By: Abel Tuter on 2022-04-05 00:20:28 PDT
Who is this request for?:Abel Tuter
Requested by:Abel Tuter
Mobile Request: iPhone, Android
Additional Comments: test
Expected output-
Mobile Request
Submitted By: | Abel Tuter on 2022-04-05 00:20:28 PDT |
Who is this request for?: | Abel Tuter |
Requested by: | Abel Tuter |
Mobile Request: | iPhone, / Android |
Additional Comments: | test3 |
Below is the email script-
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template, /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, /* Optional GlideRecord */ event) {
template.print('<table class="test-notif-summary" align="center">');
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.sysapproval);
var catalogItem = ritm.cat_item.name;
var requestedFor = ritm.request.requested_for.getDisplayValue();
var submittedOn = ritm.request.sys_created_on.getDisplayValue();
var submittedBy = ritm.request.opened_by.getDisplayValue();
var picture = ritm.cat_item.picture.getDisplayValue();
var imgSrc = '';
if (JSUtil.notNil(picture)) {
imgSrc = picture + '?t=small';
} else {
imgSrc = 'test-default.png';
}
// Get Owned Variables for Requested Item and sort by Order.
var variableSection = '';
//TO remove false variabes
var ownvar = new GlideRecord('sc_item_option_mtom');
ownvar.addQuery('request_item.number', ritm.number);
ownvar.orderBy('sc_item_option.item_option_new.getDisplayValue()', '!=', 'Order Guide');
ownvar.addQuery('sc_item_option.value', '!=', '');
var removefalse=ownvar.addQuery('sc_item_option.value','!=',false); //added
removefalse.addOrCondition('sc_item_option.value','!=','false'); //added
ownvar.orderBy('sc_item_option.order');
ownvar.query();
while (ownvar.next()) {
var field = ownvar.sc_item_option.item_option_new;
var fieldValue = ownvar.sc_item_option.item_option_new.name;
var fieldapprover = ownvar.sc_item_option.item_option_new.u_visible_on_approvers;
if (fieldapprover == true && fieldValue != 'tande_card_type' ) {
variableSection = variableSection + '<p class="test-notif-summary-row-details-field"><span class="test-notif- bold">' + field.getDisplayValue() + ':</span><span>' +
ritm.variables[fieldValue].getDisplayValue() + '</span></p>';
}
}
if (ritm.cat_item.price > 0) {
variableSection = variableSection + '<b>Cost:</b> ' + ritm.cat_item.price;
}
template.print(
'<tr class="test-notif-summary-row">' +
'<td class="test-notif-summary-row-img"><img src="' + imgSrc + '" /></td>' +
'<td class="test-notif-summary-row-details">' +
'<p class="test-notif-summary-item">' + catalogItem + '</p>' +
'<p class="test-notif-summary-row-details-field"><span class="test-notif-bold">Submitted By:</span> <span>' + submittedBy + ' on ' + submittedOn + '</span></p>' +
variableSection +
'</td>' +
'</tr>'
);
template.print('</table>');
})(current, template, email, email_action, event);
Note- Variable 'variableSection' has field name and values of last 2 fields shown in the content. For reference, see line no 34 and 39 of the script.
Could someone help me to achieve this?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 07:30 AM
Hi,
I have provided the logic below to remove false values
aligning can be done from your side
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
template.print("<table><tbody>");
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.sysapproval);
ritm.query();
if(ritm.next()){
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != 'false'){
template.print("<tr>");
template.print("<td>");
template.print(label);
template.print("</td>");
template.print("<td>");
template.print(value);
template.print("</td>");
template.print("</tr>");
}
}
}
template.print("</table></tbody>");
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 07:15 AM
I am getting the output as-
Mobile Request Submitted By: Abel Tuter on 2022-04-05 12:50:28 IST |
Who is this request for? | Abel Tuter |
Requested by | Abel Tuter |
Mobile Request | Iphone, Android |
OPN REQUEST | false |
Additional Comments | test3 |
I don't want the variables having false values(OPN Request- false)-
Could you provide me the logic how to remove the false values in the script you have provided?
Below is the script to remove false values- But i dont know how to put the below code in the code you have provided?
var ownvar = new GlideRecord('sc_item_option_mtom');
ownvar.addQuery('request_item.number', ritm.number);
ownvar.orderBy('sc_item_option.item_option_new.getDisplayValue()', '!=', 'Order Guide');
ownvar.addQuery('sc_item_option.value', '!=', '');
var removefalse=ownvar.addQuery('sc_item_option.value','!=',false); //added
removefalse.addOrCondition('sc_item_option.value','!=','false'); //added
ownvar.orderBy('sc_item_option.order');
ownvar.query();
while (ownvar.next()) {
var field = ownvar.sc_item_option.item_option_new;
var fieldValue = ownvar.sc_item_option.item_option_new.name;
var fieldapprover = ownvar.sc_item_option.item_option_new.u_visible_on_approvers;
if (fieldapprover == true && fieldValue != 'tande_card_type' ) {
variableSection = variableSection + '<p class="test-notif-summary-row-details-field"><span class="test-notif- bold">' + field.getDisplayValue() + ':</span><span>' +
ritm.variables[fieldValue].getDisplayValue() + '</span></p>';
Also could we move the table to the right(just below Submitted by)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 07:30 AM
Hi,
I have provided the logic below to remove false values
aligning can be done from your side
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
template.print("<table><tbody>");
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.sysapproval);
ritm.query();
if(ritm.next()){
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != 'false'){
template.print("<tr>");
template.print("<td>");
template.print(label);
template.print("</td>");
template.print("<td>");
template.print(value);
template.print("</td>");
template.print("</tr>");
}
}
}
template.print("</table></tbody>");
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader