how to get variable set values in email script from flow

mrunalnikhi
Tera Contributor

I am trying to read asset varibles from variable set. But it is coming as empty value with below script.
what is correct way to read array.object variable in email script. PFA for ref.

Email Script:

(function runMailScript(current, template, email, email_action, event) {

     var mrvs = current.variables.mrvs_asset_details;

    gs.info('MRVS rows: ' + current.variables.mrvs_asset_details.getRowCount());

    template.print('<table border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse;">');

    template.print(
        '<tr>' +
        '<th>S.No</th>' +
        '<th>Asset Tag</th>' +
        '<th>Serial Number</th>' +
        '<th>User ID</th>' +
        '<th>Employee Name</th>' +
        '<th>Location</th>' +
        '<th>Department</th>' +
        '<th>Asset Type</th>' +
        '</tr>'
    );

    for (var i = 0; i < mrvs.getRowCount(); i++) {

        var row = mrvs.getRow(i);

        template.print('<tr>');

        template.print('<td>' + (i + 1) + '</td>');
        template.print('<td>' + row.asset_tag + '</td>');
        template.print('<td>' + row.serial_number + '</td>');
        template.print('<td>' + row.mid + '</td>');
        template.print('<td>' + row.emp_name + '</td>');
        template.print('<td>' + row.location + '</td>');
        template.print('<td>' + row.department + '</td>');
        template.print('<td>' + row.asset_type + '</td>');

        template.print('</tr>');
    }

    template.print('</table>');

})(current, template, email, email_action, event);
mrunalnikhi_1-1795755774799.png

 


 

mrunalnikhi_2-1795755810077.pngmrunalnikhi_3-1795755909834.pngmrunalnikhi_4-1795756094528.png

 

7 REPLIES 7

HasanM
Kilo Sage

Hi @mrunalnikhi,

Your script looks right for a notification on sc_req_item, so the empty values usually come from one of these:

  1. Internal names. mrvs_asset_details must be the Internal name on the multi-row variable set record, not its title. Each column (asset_tag, serial_number, mid and so on) must use the variable names inside the MRVS.

  2. Timing. If the flow sends the email as soon as the RITM is created, the MRVS rows may not be saved yet. Move the Send Notification or Send Email step later in the flow, or add a short wait before it.

  3. Check what arrives. Add this to the script and look at the system log:

gs.info('MRVS: ' + current.variables.mrvs_asset_details);

If the log shows the rows as JSON but your table is still empty, read them like this:

var rows = JSON.parse(current.variables.mrvs_asset_details.toString() || '[]');
for (var i = 0; i < rows.length; i++) {
var r = rows[i];
template.print('<tr><td>' + (i + 1) + '</td><td>' + r.asset_tag + '</td><td>' + r.serial_number + '</td><td>' + r.mid + '</td><td>' + r.emp_name + '</td><td>' + r.location + '</td><td>' + r.department + '</td><td>' + r.asset_type + '</td></tr>');
}

Reference variables such as location and department return sys_ids, so look up their display values if you need names.

If this helped, please mark it as the accepted solution.

@HasanM,

 

Notification is on sc_req_item table in the screenshots.

I am in flow itself getting empty value? but on RITM I can see details under variables

 

Ankur Bawiskar
Tera Patron

@mrunalnikhi 

script looks fine to me

Did you print what came in logs?

gs.info('MRVS rows: ' + current.variables.mrvs_asset_details.getRowCount());

// also add this

gs.info('MRVS data: ' + JSON.stringify(current.variables.mrvs_asset_details));

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏