Multi Row Variable Set

kirankr2061
Tera Contributor

The below is my email script I can able to access all the variables but I could'nt able to access the MRVS values I found this 

 var mrvs = new GlideappVariablePoolQuestionSet(); This is this the way to access the mrvs values in the email script 
and here 
(row.getQuestionSetName() === 'tenable_add_role') - MRVS name 

 var account = row.getValue('ten_mrvscloud_account_name');
            var users = row.getValue('ten_mrvs_user');
            var roles = row.getValue('ten_mrvs_roles');
The above are variables all are list collectors how can approach this 


Email script 
(function runMailScript(current, template, email, email_action, event) {
    var emailBody = '';

    var owner = current.variables.ten_cloud_account_owner.name;
    var requestedFor = current.variables.requested_for.email;
    var cloud_provider = current.variables.ten_cloud_provider;
    var t_type = current.variables.ten_members;
    var type = (t_type == 'ten_users') ? 'Users' : 'Groups';

    emailBody += '<p>Hello ' + owner + ',</p>';
    emailBody += '<p>A request has been submitted via the Cloud Infrastructure & Entitlement Management Rainier catalog to onboard the following cloud accounts under your ownership to the Tenable platform. Below are the details of the users and their respective roles for each cloud account which will be added as a new eligibility onto the Tenable platform.</p>';

    emailBody += '<p>Requested for: ' + requestedFor + '<br>';
    emailBody += 'Creating New eligibility onto the Tenable platform<br>';
    emailBody += 'Cloud Provider: ' + cloud_provider + '<br>';
    emailBody += 'Action: Add New eligibility<br>';
    emailBody += 'Type: ' + type + '</p>';

    emailBody += '<p>Please note that the mentioned users will be assigned the respective roles for the cloud accounts listed below.</p>';
    emailBody += '<table border="1"><tr><th>Account</th><th>Users</th><th>Roles</th></tr>';

    var mrvs = new GlideappVariablePoolQuestionSet();
    mrvs.setRequestID(current.sys_id);
    var rows = mrvs.getRows();

    while (rows.hasNext()) {
        var row = rows.next();

        // Filter only rows belonging to the 'tenable_add_role' variable set
        if (row.getQuestionSetName() === 'tenable_add_role') {
            var account = row.getValue('ten_mrvscloud_account_name');
            var users = row.getValue('ten_mrvs_user');
            var roles = row.getValue('ten_mrvs_roles');

            emailBody += '<tr>';
            emailBody += '<td>' + account + '</td>';
            emailBody += '<td>' + users + '</td>';
            emailBody += '<td>' + roles + '</td>';
            emailBody += '</tr>';
        }
    }

    emailBody += '</table>';
    emailBody += '<p>We kindly request you to review the request and provide your approval or rejection.</p>';
    emailBody += '<p>Thank you.</p>';

    template.print(emailBody);
})(current, template, email, email_action, event);
3 ACCEPTED SOLUTIONS

@kirankr2061 

Hope you are doing good.

Did my reply answer your question?

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

View solution in original post

Aniket Chavan
Tera Sage
Tera Sage

Hello @kirankr2061 ,

I’ve implemented a similar use case in my instance, where we send email notifications including both standard variables and MRVS data.

 

Based on that setup, I’ve tried to fix and improve your email script accordingly. Please try the updated version below. Let me know how it works for you — and if you run into any issues, I’ll be happy to help debug it further:

 

(function runMailScript(current, template, email, email_action, event) {
    var emailBody = '';

    var owner = current.variables.ten_cloud_account_owner.name;
    var requestedFor = current.variables.requested_for.email;
    var cloud_provider = current.variables.ten_cloud_provider;
    var t_type = current.variables.ten_members;
    var type = (t_type == 'ten_users') ? 'Users' : 'Groups';

    emailBody += '<p>Hello ' + owner + ',</p>';
    emailBody += '<p>A request has been submitted via the Cloud Infrastructure & Entitlement Management Rainier catalog to onboard the following cloud accounts under your ownership to the Tenable platform. Below are the details of the users and their respective roles for each cloud account which will be added as a new eligibility onto the Tenable platform.</p>';

    emailBody += '<p><strong>Requested for:</strong> ' + requestedFor + '<br>';
    emailBody += '<strong>Cloud Provider:</strong> ' + cloud_provider + '<br>';
    emailBody += '<strong>Action:</strong> Add New eligibility<br>';
    emailBody += '<strong>Type:</strong> ' + type + '</p>';

    emailBody += '<p>Please note that the mentioned users will be assigned the respective roles for the cloud accounts listed below.</p>';

    // Start table
    emailBody += '<table border="1" cellpadding="5" cellspacing="0">';
    emailBody += '<tr><th style="background-color:#f2f2f2;">Account</th><th style="background-color:#f2f2f2;">Users</th><th style="background-color:#f2f2f2;">Roles</th></tr>';

    try {
        // Access MRVS JSON
        var mrvsJSON = current.variables.tenable_add_role;
        if (mrvsJSON) {
            var rows = JSON.parse(mrvsJSON);
            rows.forEach(function(row) {
                var account = row.ten_mrvscloud_account_name || '';
                var users = row.ten_mrvs_user || '';
                var roles = row.ten_mrvs_roles || '';

                emailBody += '<tr>';
                emailBody += '<td style="color:#008fd0;">' + account + '</td>';
                emailBody += '<td style="color:#008fd0;">' + users + '</td>';
                emailBody += '<td style="color:#008fd0;">' + roles + '</td>';
                emailBody += '</tr>';
            });
        } else {
            emailBody += '<tr><td colspan="3"><i>No MRVS data available.</i></td></tr>';
        }
    } catch (err) {
        emailBody += '<tr><td colspan="3"><i>Error parsing MRVS data.</i></td></tr>';
        gs.error('Error in email script MRVS parsing: ' + err.message);
    }

    emailBody += '</table>';
    emailBody += '<p>We kindly request you to review the request and provide your approval or rejection.</p>';
    emailBody += '<p>Thank you.</p>';

    template.print(emailBody);
})(current, template, email, email_action, event);

 

🔹 Please mark Correct if this solves your query, and 👍 Helpful if you found the response valuable.

 

Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024

View solution in original post

Community Alums
Not applicable

hi @kirankr2061 ,

ou’re very close, and you’re on the right track using GlideappVariablePoolQuestionSet to access MRVS data inside an email script.
A couple of points to keep in mind when working with MRVS and list collectors inside MRVS in an email context:

1. GlideappVariablePoolQuestionSet vs. GlideMultiRowVariableSet

You correctly used GlideappVariablePoolQuestionSet because you're inside a Request Item (RITM) email script and want to pull variables related to the MRVS.
But note: when MRVS has list collectors inside, those list collectors store sys IDs as comma-separated values.

 

(function runMailScript(current, template, email, email_action, event) {
    var emailBody = '';

    // Get simple variables
    var owner = current.variables.ten_cloud_account_owner.name;
    var requestedFor = current.variables.requested_for.email;
    var cloud_provider = current.variables.ten_cloud_provider;
    var t_type = current.variables.ten_members;
    var type = (t_type == 'ten_users') ? 'Users' : 'Groups';

    emailBody += '<p>Hello ' + owner + ',</p>';
    emailBody += '<p>A request has been submitted via the Cloud Infrastructure & Entitlement Management Rainier catalog to onboard the following cloud accounts under your ownership to the Tenable platform. Below are the details of the users and their respective roles for each cloud account which will be added as a new eligibility onto the Tenable platform.</p>';

    emailBody += '<p>Requested for: ' + requestedFor + '<br>';
    emailBody += 'Creating New eligibility onto the Tenable platform<br>';
    emailBody += 'Cloud Provider: ' + cloud_provider + '<br>';
    emailBody += 'Action: Add New eligibility<br>';
    emailBody += 'Type: ' + type + '</p>';

    emailBody += '<p>Please note that the mentioned users will be assigned the respective roles for the cloud accounts listed below.</p>';
    emailBody += '<table border="1"><tr><th>Account</th><th>Users</th><th>Roles</th></tr>';

    // Helper function to convert comma-separated sys_ids to display names
    function getDisplayValues(sys_ids, table, displayField) {
        if (!sys_ids) return '';
        var ids = sys_ids.split(',');
        var names = [];
        for (var i = 0; i < ids.length; i++) {
            var gr = new GlideRecord(table);
            if (gr.get(ids[i])) {
                names.push(gr.getValue(displayField));
            }
        }
        return names.join(', ');
    }

    // Get MRVS data
    var mrvs = new GlideappVariablePoolQuestionSet();
    mrvs.setRequestID(current.sys_id);  // for RITM; use current.request.sys_id for sc_request if needed

    var rows = mrvs.getRows();
    while (rows.hasNext()) {
        var row = rows.next();

        // Only process the rows from your target MRVS
        if (row.getQuestionSetName() === 'tenable_add_role') {
            var account = row.getValue('ten_mrvscloud_account_name');

            // Resolve list collector sys_ids to display values
            var users = getDisplayValues(row.getValue('ten_mrvs_user'), 'sys_user', 'name'); 
            var roles = getDisplayValues(row.getValue('ten_mrvs_roles'), 'your_roles_table', 'name'); 
            // Replace 'your_roles_table' and 'name' if needed

            emailBody += '<tr>';
            emailBody += '<td>' + account + '</td>';
            emailBody += '<td>' + users + '</td>';
            emailBody += '<td>' + roles + '</td>';
            emailBody += '</tr>';
        }
    }

    emailBody += '</table>';
    emailBody += '<p>We kindly request you to review the request and provide your approval or rejection.</p>';
    emailBody += '<p>Thank you.</p>';

    template.print(emailBody);
})(current, template, email, email_action, event);

 

  • Replace 'your_roles_table' with the table your ten_mrvs_roles list collector points to.

  • Replace 'name' with the actual display field of that table (e.g., maybe u_role_name or similar).

  • Same idea applies if your ten_mrvs_user points to something other than sys_user.

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@kirankr2061 

this link has solution, please enhance it

How to Display Multi Row Variable set (MRVS) data in a notification 

also check this

Multi-row variable set in Notifications via Notifications Email Script 

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

@kirankr2061 

Hope you are doing good.

Did my reply answer your question?

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

Aniket Chavan
Tera Sage
Tera Sage

Hello @kirankr2061 ,

I’ve implemented a similar use case in my instance, where we send email notifications including both standard variables and MRVS data.

 

Based on that setup, I’ve tried to fix and improve your email script accordingly. Please try the updated version below. Let me know how it works for you — and if you run into any issues, I’ll be happy to help debug it further:

 

(function runMailScript(current, template, email, email_action, event) {
    var emailBody = '';

    var owner = current.variables.ten_cloud_account_owner.name;
    var requestedFor = current.variables.requested_for.email;
    var cloud_provider = current.variables.ten_cloud_provider;
    var t_type = current.variables.ten_members;
    var type = (t_type == 'ten_users') ? 'Users' : 'Groups';

    emailBody += '<p>Hello ' + owner + ',</p>';
    emailBody += '<p>A request has been submitted via the Cloud Infrastructure & Entitlement Management Rainier catalog to onboard the following cloud accounts under your ownership to the Tenable platform. Below are the details of the users and their respective roles for each cloud account which will be added as a new eligibility onto the Tenable platform.</p>';

    emailBody += '<p><strong>Requested for:</strong> ' + requestedFor + '<br>';
    emailBody += '<strong>Cloud Provider:</strong> ' + cloud_provider + '<br>';
    emailBody += '<strong>Action:</strong> Add New eligibility<br>';
    emailBody += '<strong>Type:</strong> ' + type + '</p>';

    emailBody += '<p>Please note that the mentioned users will be assigned the respective roles for the cloud accounts listed below.</p>';

    // Start table
    emailBody += '<table border="1" cellpadding="5" cellspacing="0">';
    emailBody += '<tr><th style="background-color:#f2f2f2;">Account</th><th style="background-color:#f2f2f2;">Users</th><th style="background-color:#f2f2f2;">Roles</th></tr>';

    try {
        // Access MRVS JSON
        var mrvsJSON = current.variables.tenable_add_role;
        if (mrvsJSON) {
            var rows = JSON.parse(mrvsJSON);
            rows.forEach(function(row) {
                var account = row.ten_mrvscloud_account_name || '';
                var users = row.ten_mrvs_user || '';
                var roles = row.ten_mrvs_roles || '';

                emailBody += '<tr>';
                emailBody += '<td style="color:#008fd0;">' + account + '</td>';
                emailBody += '<td style="color:#008fd0;">' + users + '</td>';
                emailBody += '<td style="color:#008fd0;">' + roles + '</td>';
                emailBody += '</tr>';
            });
        } else {
            emailBody += '<tr><td colspan="3"><i>No MRVS data available.</i></td></tr>';
        }
    } catch (err) {
        emailBody += '<tr><td colspan="3"><i>Error parsing MRVS data.</i></td></tr>';
        gs.error('Error in email script MRVS parsing: ' + err.message);
    }

    emailBody += '</table>';
    emailBody += '<p>We kindly request you to review the request and provide your approval or rejection.</p>';
    emailBody += '<p>Thank you.</p>';

    template.print(emailBody);
})(current, template, email, email_action, event);

 

🔹 Please mark Correct if this solves your query, and 👍 Helpful if you found the response valuable.

 

Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024

Its working Thank You @Aniket Chavan