Dynamically Send Catalog Variables & Multi-Row Variable Sets in Email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2025 08:52 AM - edited 06-15-2025 10:18 PM
Hello Community,
Have you ever needed to send catalog item variables via email, especially Multi-Row Variable Sets (MRVS), but struggled to present them in a clean, readable format? I recently tackled this challenge and wanted to share my approach.
Usually, we use the GlideappVariablePoolQuestionSet API to retrieve catalog variables. While it works well for standard variables, it doesn't present multi-row data in a clean tabular structure, especially when sending it over email.
To overcome this, I used the GlobalServiceCatalogUtil API. It makes it easier to extract both single variables and MRVS values and format them in a nested table structure for clear readability.
Mail Script Code:-
(function runMailScript(current, template, email, email_action, event) {
template.print('<table border="1">');
var grTask = new GlideRecord('sc_req_item');
if (grTask.get(current.sysapproval)) {
var ans = new global.GlobalServiceCatalogUtil().getVariablesForTask(grTask, true);
for (var i = 0; i < ans.length; i++) {
var variable = ans[i];
// Regular variables
if (!variable.multi_row) {
template.print("<tr>");
template.print("<td style='width:50%'>" + variable.label + "</td>");
template.print("<td>" + variable.display_value + "</td>");
template.print("</tr>");
}
// Multi-row variable sets
if (variable.multi_row && variable.table_variable) {
var rows = variable.table_variable;
if (rows.length > 0) {
// Print MRVS title row
template.print("<tr><td colspan='2'><b>" + variable.label + "</b></td></tr>");
// Print MRVS header
var headers = rows[0].map(function(field) {
return field.label;
});
template.print("<tr><td colspan='2'><table border='1' style='width:100%'><tr>");
for (var h = 0; h < headers.length; h++) {
template.print("<th>" + headers[h] + "</th>");
}
template.print("</tr>");
// Print each row of MRVS
for (var j = 0; j < rows.length; j++) {
template.print("<tr>");
var row = rows[j];
for (var k = 0; k < row.length; k++) {
var field = row[k];
template.print("<td>" + field.display_value + "</td>");
}
template.print("</tr>");
}
template.print("</table></td></tr>");
}
}
}
}
template.print("</table>");
})(current, template, email, email_action, event);
Output Format:-
Variables
| Field Name | Field Value |
| -------------------- | ----------------- |
| Request Type | External Employee |
| Location | New York Office |
| Requested Start Date | 2025-07-01 |
Multi-Row Variable Set Name
| Module | Use of Module | Plugin |
| ---------- | ---------------------------- | -------------------------------- |
| ITSM | Incident & Change Management | ITSM Standard Plugin |
| CSM | Manage Customer Interactions | Customer Service Management Core |
| CMDB | Asset & CI Tracking | Configuration Management |
If you've implemented a similar solution or have a better approach, I'd love to hear your thoughts. Hopefully, this helps anyone trying to make email notifications more dynamic and user-friendly in ServiceNow!
- Labels:
-
Request Management
-
Service Catalog
- 494 Views