Write a HTML table as an additional comment to a RITM
ServiceNow Blog
·
Feb 02, 2025
·
article
var table_html = '
';var rowIndex = 0;
// Add table headers with styles
table_html += '
' +'
' +'
' +'
';for (var key in json) {
if (json.hasOwnProperty(key)) {
rowIndex++;
var rowColor = (rowIndex % 2 === 0) ? '#f2f2f2' : '#ffffff'; // Alternate colors
table_html += '
' +'
' +'
' +'
';}
}
table_html += '
| Name | Value |
|---|---|
| ' + key + ' | ' + json[key] + ' |
return table_html;
},
getInfoAttributes: function(json_payload) {
/*
Takes a JSON payload with key value pairs and strips out only those with 'info' in their name.
*/
var json_payload2 = json_payload.replace(/\\"/g, '"');//strip out the escape backslash
var jsonPayload3 = json_payload2.replace(/\[(.*?)\]/g, function(match) {
return match.replace(/"/g, "'"); //replace double quotes within square brackets (array) with single quotes
});
var result = {};
var jsonPayload4 = JSON.parse(jsonPayload3);
// Loop through all keys in the JSON object
for (var key in jsonPayload4) {
if (jsonPayload4.hasOwnProperty(key) && key.toLowerCase().includes("info")) {
result[key] = jsonPayload4[key];
}
}
return result;
},
Flow action:
http://www.cloudminus89.com/2025/02/write-html-table-as-additional-comment.html