- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 08:01 AM
I'm modifying the show_ritm_option_vals Email Script to align with a new Catalog Item.
Unfortunately I noticed it was including ALL variables which made the form hard to read.
I removed the bulk by adding a check to ensure the displaylable != 'false' but I'm still getting unwanted content which I need to remove.
How can I remove these "formatter" labels?
I also have multiple display labels which aren't necessary
The OOTB script for displaying all options is the following:
template.print(" Options:<br><br>");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " <strong>" + vs.get(i).getDisplayValue() + "</strong><br>");
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2024 12:59 PM
Fixed this issue.
The solution wasn't pretty but a fairly stacked if conditional check nested within the for loop ensured non-compliance variables were excluded. There's likely a cleaner solution but this is currently working, likely a version 1.0 until I have time to revisit.
if(vs2.get(ii).getLabel() != '' &&
vs2.get(ii).getDisplayValue() != 'false' &&
!vs2.get(ii).getLabel().includes('formatter') &&
!vs2.get(ii).getLabel().includes('requires the following') &&
!vs2.get(ii).getLabel().includes('do not require'))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 08:06 AM
Hello,
To modify the show_ritm_option_vals email script and ensure that unwanted content like "formatter" labels and unnecessary display labels are removed, you can take the following steps:
1. Skip Formatter Variables:
Formatters (such as section breaks) can appear in the results and clutter the display. You can filter them out by checking the type of the variable. If a variable is a formatter, it will often have specific types such as "formatter", "macro", etc. You can check for these and exclude them from the output.
Add a check to skip formatters:
template.print("Options:<br><br>");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
var question = vs.get(i);
// Check if the question is a formatter or has display label set to false
var questionType = question.getType();
var displayLabel = question.getDisplayLabel();
// Skip formatters or questions where displayLabel is false or empty
if (questionType == 'formatter' || displayLabel == 'false' || displayLabel == '') {
continue;
}
// Print the label and value
template.space(4);
template.print(' ' + question.getLabel() + " <strong>" + question.getDisplayValue() + "</strong><br>");
}
Explanation:
Check for the questionType:
- The code checks question.getType() to filter out formatters and other unnecessary elements. If the type is "formatter", the loop will skip to the next variable.
Check for displayLabel:
- If the display label is set to false or is empty (displayLabel == 'false' || displayLabel == ''), the loop will skip the question to avoid including unnecessary or hidden labels.
2. Remove Duplicate Labels:
If you have multiple display labels that are not needed, you can use a Set to keep track of the labels that have already been printed, ensuring you only show each label once.
template.print("Options:<br><br>");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
var printedLabels = new Set(); // To track unique labels
for (var i = 0; i < vs.size(); i++) {
var question = vs.get(i);
// Check if the question is a formatter or has display label set to false
var questionType = question.getType();
var displayLabel = question.getDisplayLabel();
// Skip formatters, empty or false display labels
if (questionType == 'formatter' || displayLabel == 'false' || displayLabel == '') {
continue;
}
// Skip if the label has already been printed
if (printedLabels.has(question.getLabel())) {
continue;
}
// Add label to the set and print the label and value
printedLabels.add(question.getLabel());
template.space(4);
template.print(' ' + question.getLabel() + " <strong>" + question.getDisplayValue() + "</strong><br>");
}
Key Adjustments:
- Tracking Printed Labels: Using a Set called printedLabels, the script ensures that each label is only printed once.
- Continued Filtering: The script continues to skip unnecessary items based on their type and display label properties.
With these changes, the email output should be much cleaner, displaying only the necessary variables while skipping unwanted formatters and duplicate display labels.
Please mark my answer helpful.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 12:02 PM
Hi @sundaram080713,
Unfortunately these script did not work and all the values were still coming through, formatter and false values included.
I do think I resolved it, however, using an includes conditional check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2024 12:59 PM
Fixed this issue.
The solution wasn't pretty but a fairly stacked if conditional check nested within the for loop ensured non-compliance variables were excluded. There's likely a cleaner solution but this is currently working, likely a version 1.0 until I have time to revisit.
if(vs2.get(ii).getLabel() != '' &&
vs2.get(ii).getDisplayValue() != 'false' &&
!vs2.get(ii).getLabel().includes('formatter') &&
!vs2.get(ii).getLabel().includes('requires the following') &&
!vs2.get(ii).getLabel().includes('do not require'))