- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 10:46 PM
This script iterates through variables in current, retrieving each variable's label and displayed value using getQuestion() and getDisplayValue(). It checks if the value is filled and prints the label and value formatted if both conditions are met, using template.print() for output.
(function runMailScript(current, template, email, email_action, event) {
// Print header for variables
template.print('Variables: <br/>');
// Retrieve elements (variables/questions) from the current context
var variables = current.variables.getElements();
// Iterate through each variable
for (var i = 0; i < variables.length; i++) {
// Get the question associated with the variable
var question = variables[i].getQuestion();
// Get label (name) of the question
var label = question.getLabel();
// Get displayed value of the question
var value = question.getDisplayValue();
// Check if the value is considered filled
var filled = value != false && value != 'false' && value != undefined && value != '';
// Print label and value if label is not empty and value is filled
if (label != '' && filled) {
template.space(4); // Add indentation
template.print(' ' + label + " = " + value + "<br/>"); // Print label and value
}
}
})(current, template, email, email_action, event);
Might be helpful for you.