
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎10-21-2020 07:11 AM
Today, I am going to share you a code snippet of Mail script which will fetch the submitted MRVS data and send it in a notification in a nice tabular format. It also returns you the display name if any reference columns exist.
Here are the steps todo
1. Create a notification on Requested Item (sc_req_item) table.
2. Inserted or updated. Inserted: True
What it contains
Call your mail script like thils
${mail_script:employment_details}
Mail Script
Name: employment_details
Script
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Fetch the MRVS data and display them as table in notification
template.print("<br>Name: " + current.variables.full_name);
template.print("<br>Date of Birth: " + current.variables.date_of_birth);
var mrvs = current.variables.employment_history; // MRVS Internal name
var rowCount = mrvs.getRowCount();
if (rowCount >= 1) {
template.print("<br<b>Employment Details</b>");
template.print("<table border =1>");
template.print("<tr>");
template.print("<th>Company</th>");
template.print("<th>Designation</th>");
template.print("<th>Start Date</th>");
template.print("<th>End Date</th>");
template.print("<th>Location</th>");
template.print("</tr>");
for (var i = 0; i < rowCount; i++) {
template.print("<tr>");
var row = mrvs.getRow(i);
template.print("<td>" + getName(row.company.toString(),'core_company') + "</td>");
template.print("<td>" + row.designation + "</td>");
template.print("<td>" + row.start_date + "</td>");
template.print("<td>" + row.end_date + "</td>");
template.print("<td>" + getName(row.location.toString(),'cmn_location') + "</td>");
template.print("</tr>");
}
template.print("</table>");
}
//This function accept sys_id and table and returns the Display name.
function getName(sys_id,tblName) {
var rec = new GlideRecord(tblName);
if(rec.get(sys_id)) {
return rec.getDisplayValue();
}
}
})(current, template, email, email_action, event);
That's it. Now submit your catalog item and test once.
Sample Output
Let me know if you have any questions in the comments below.
Related MRVS articles that I Wrote:
- Disable buttons in MultiRow Variable Set
- Populate the value of a field of Catalog item into the Multi Row Variable Set
- How to add rows dynamically in Multi Row Variable set (MRVS) based on input value of Catalog item
- Prefill data in Multi Row Variable Sets
Mark the article as helpful and bookmark if you found it useful.
Regards,
Asif
2020 ServiceNow Community MVP
- 14,034 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How to convert same thing in html to pdf?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks, really work!!!!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This works perfectly and displays nicely, but I have a question: what is the best way to get the choice from a select box to display? I'm either getting the sys_name, or if i use .getDisplayValue() or getValue, it's either undefined or picks up the email signature (which is the next line after the table in the notification)
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Use Ankur's solution in this post to create a GlideRecord to lookup to get the reference values to display. Just worked perfectly for me.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
i have created a varaible set in one of my catalog , the varaible set data is coming to ritm and sctask.
i need that varaible set data to be displayed in my approval widget in portaL where approver can open ritm and approve the ritm.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks, really work!!!!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Team,
I have created one multi-row variable set with limit of 5 and I wanted to add one checkbox and one multi line text in my catalog item. If I click on check-box then whatever data I have added in my multi-row variable set all the data will be shown in multi line text.
Can anyone help me with this problem statement?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @asifnoor ,
How can I show Multiple variable set in notification using Flow Designer?
Thanks,
Sam