unable to insert mvrs data into email notification

kam4
Tera Contributor

Hi Al,

I have an issue where i have create an email notification and try to insert mvrs data into the email notification content but it was not able to show anything, I attach the screenshot for your reference.

 

email notification Table

Requested Item (SC_re_item)

 

Email script

namePrintMRVSData

scripts:

"(function runMailScript(current, template, email, email_action, event) {
// Get the sys_id of the requested item
var ritmSysId = current.sys_id;

// Get the MRVS data (example: 'u_mrvs_variable_name')
var mrvsData = current.variables.u_vs_user_info_celonis; // Replace with your MRVS variable name

// Check if data exists
if (mrvsData && mrvsData.getRowCount() > 0) {
var tableHtml = '<table>';
tableHtml += '<tr><th>Column 1</th><th>Column 2</th></tr>'; // Replace with your column headers

for (var i = 0; i < mrvsData.getRowCount(); i++) {
var row = mrvsData.getRow(i);
tableHtml += '<tr>';
tableHtml += '<td>' + row.u_region + '</td>'; // Replace with your column values
tableHtml += '<td>' + row.u_region + '</td>';
tableHtml += '</tr>';
}
tableHtml += '</table>';

 

template.print(tableHtml);
} else {
template.print('No data found in Multi-row variable set.');
}
})(current, template, email, email_action, event);"

 

 

 

10 REPLIES 10

@kam4 

sorry didn't get.

is it not working or working fine?

share some screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Dear Ankur,

Sorry it was not able to show the information after applying your solution and here is the screenshot

@kam4 

does your catalog item have MRVS in it?

did you add logs and see?

you used the wrong script and not the one I shared

here is my script

(function runMailScript(current, template, email, email_action, event) {
    // Replace with your actual MRVS variable name
    var mrvsVarName = 'u_vs_user_info_celonis';
    var mrvsData = current.variables[mrvsVarName];

    if (mrvsData) {
        // Parse the JSON string
        var rows = JSON.parse(mrvsData + '');
        if (rows.length > 0) {
            var tableHtml = '<table border="1"><tr><th>Region</th></tr>';
            for (var i = 0; i < rows.length; i++) {
                tableHtml += '<tr><td>' + rows[i].u_region + '</td></tr>';
            }
            tableHtml += '</table>';
            template.print(tableHtml);
        } else {
            template.print('No data found in Multi-row variable set.');
        }
    } else {
        template.print('No data found in Multi-row variable set.');
    }
})(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
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Dear Ankur,

I have 2 question.

1. Do we have to distinguish between email notification from table is requested item (sc_req_item) or Approval (sysapproval_approver)? because the email notification is from the table Approval (sysapproval_approver).

2. Do I need to put the current.variable name from the mvrs variables? if yes the variables i create is current.variables.u_region

TMKAM_0-1750228405903.png

I attach the MVRS variable for your reference.

TMKAM_0-1750229955872.png

 

I hope to get an answer from you.

Thank You

Regards,

TMKam

 

@TMKAM 

yes you need to distinguish between those 2 tables

if notification is on RITM then you can access directly

if notification is on approval then you need to query RITM and then use that GlideRecord object.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader