asifnoor
Kilo Patron

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

find_real_file.png

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

find_real_file.png

Let me know if you have any questions in the comments below.

Related MRVS articles that I Wrote:

Mark the article as helpful and bookmark if you found it useful.


Regards,
Asif
2020 ServiceNow Community MVP

Comments
kunal27
Giga Expert

How to convert same thing in html to pdf?

 

Nat_lia2
Tera Explorer

Thanks, really work!!!!!

Monicask
Mega Expert

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)

Tehilla Garfink
Tera Contributor

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.

Midikeri Naresh
Tera Contributor

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.

 

Qamber Ali
Tera Contributor

Thanks, really work!!!!!

priyanka1028
Tera Contributor

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?

Samiksha2
Mega Sage

Hello @asifnoor ,
How can I show Multiple variable set in notification using Flow Designer?

 

Thanks,
Sam

Version history
Last update:
‎10-21-2020 07:11 AM
Updated by: