Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 10:05 PM
did you print in logs?
I updated these lines, please check
(function() {
// Get current RITM (Requested Item) sys_id from the current record
var ritmSysId = current.sys_id;
// Load variable pool for the RITM
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
// Get all variables in a flat list (including those in variable sets)
var vs = set.getFlatQuestions();
// Define the desired variable labels in the specific order they should appear in the CSV
var desiredLabels = [
"Variable01", "Variable02", "Variable03", "Variable04",
"Variable05", "Variable06", "Variable07",
"Variable08", "Variable09", "Variable10", "Variable11",
"CheckBox1", "CheckBox2", "Checkbox3"
];
// Create a map (dictionary) to store label → display value pairs
var labelValueMap = {};
for (var i = 0; i < vs.size(); i++) {
var question = vs.get(i);
var label = question.getLabel();
var displayValue = question.getDisplayValue();
//REPLACED WITH CORRECT VALUES
if (["CheckBox1", "CheckBox2", "CheckBox3"].indexOf(label) !== -1) {
var rawValue = displayValue;
var getValue = (rawValue === 'true') ? 'Yes' : (rawValue === 'false') ? 'No' : 'Unknown';
gs.info('Inside variable' + label + ' value is' + getValue);
labelValueMap[label] = getValue;
} else {
labelValueMap[label] = displayValue;
}
}
// Prepare arrays to hold CSV headers and corresponding values
var headers = [];
var values = [];
// Loop through the desired labels in order and build the CSV rows
for (var j = 0; j < desiredLabels.length; j++) {
var lbl = desiredLabels[j];
headers.push(lbl); // Add the label to the header row
values.push(labelValueMap[lbl] || ""); // Add the value if found, else empty string
}
// Combine headers and values into a single CSV-formatted string
var csvContent = headers.join(",") + "\n" + values.join(",");
// Attach the generated CSV file to the current RITM record
var attachment = new GlideSysAttachment();
var fileName = "Export.csv";
attachment.write(current, fileName, "text/csv", csvContent);
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader