We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Parsing

PatlalaShaR
Mega Expert

Hi Everyone Can someone help me with how to parse the multi row variable set to human readable in email body. Thanks in advance.

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@PatlalaShaR 

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 

Multi-Row Variable Sets: Composing approval and task descriptions 

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

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

Hi @Ankur Bawiskar  Thanks for your response can we do this in send email action in flow or do we need to create a separate notification and email script, please suggest how to proceed further.

 

@PatlalaShaR 

send email does allow scripting option but better go with notification and email script

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

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

Tanushree Maiti
Tera Patron

Hi @PatlalaShaR 

You can use an Email Notification Script (Mail Script). MRVS data is stored as a JSON string, which requires server-side parsing to display as a structured HTML table.

 

Sample script /not tested:

Name: get_mrvs_data

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

    var mrvsData = current.variables.your_mrvs_internal_name;  // replace 'your_mrvs_internal_name' with yours

    if (mrvsData && mrvsData != '[]') {

        var mrvsObj = JSON.parse(mrvsData);

        template.print("<table border='1' style='border-collapse: collapse; width: 100%;'>");

        template.print("<tr style='background-color: #f2f2f2;'>");

        template.print("<th style='padding: 8px;'>Column 1 Label</th>");

        template.print("<th style='padding: 8px;'>Column 2 Label</th>");

        template.print("</tr>");

        for (var i = 0; i < mrvsObj.length; i++) {

            template.print("<tr>");

             template.print("<td style='padding: 8px;'>" + mrvsObj[i].variable_name_1 + "</td>"); // replace with correct variable name

            template.print("<td style='padding: 8px;'>" + mrvsObj[i].variable_name_2 + "</td>");

            template.print("</tr>");

        }

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

    } else {

        template.print("No items requested.");

    }

})(current, template, email, email_action, event);

 

In the Message HTML field of your Email Notification, call the script : ${mail_script:get_mrvs_data}

 

Refer: KB0743684 How to access multi-row variable set data from a script 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti