- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 05:20 AM - edited 05-27-2024 05:21 AM
Hi All,
We have an existing script to show the RITM variables in the notification. However, its also showing the variables with false values. Can you suggest how to hide the false variable value from the below script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 05:26 AM
Hi @Koyel Guha ,
Check the below code:
template.print("<p></p>Requested items:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while (gr.next()) {
var stage = gr.stage.getDisplayValue();
if (JSUtil.nil(stage))
stage = gr.stage.getChoiceValue();
template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + ", Stage: " + stage + "\n");
template.print(" \n ");
template.print(" More details:\n");
for (key in gr.variables) {
var v = gr.variables[key];
var question = v.getGlideObject().getQuestion();
var label = question.getLabel();
var displayValue = v.getDisplayValue();
if (label && displayValue && displayValue.toLowerCase() !== 'false') {
template.space(4);
template.print(' ' + label + " = " + displayValue + "\n");
}
}
}
Result:
1. here variable "advance" is empty. In email body the above script didn't print "advance"
2. here variable "tt" is not checked & select box "Bu 2" is false & "advance" is empty. In email body the above script didn't print "advance"
If my answer helped you in any way, please mark it as helpful or correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 05:47 AM
Hi @Koyel Guha
Please check the below code. Tested in PDI & working as expected.
If the variable is inactive the below code ignores the value.
template.print("<p></p>Requested items:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while (gr.next()) {
var stage = gr.stage.getDisplayValue();
if (JSUtil.nil(stage))
stage = gr.stage.getChoiceValue();
template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + ", Stage: " + stage + "\n");
template.print(" \n ");
template.print(" More details:\n");
for (var key in gr.variables) {
var v = gr.variables[key];
var question = v.getGlideObject().getQuestion();
if (question.active && question.getLabel() != '') { //checking active or not
var displayValue = v.getDisplayValue();
if (displayValue) {
template.space(4);
template.print(' ' + question.getLabel() + " = " + displayValue + "\n");
}
}
}
}
If my answer helped you in any way, please mark it as helpful or correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 03:20 AM
Hi Sai,
Thank you for your response.
Could you please explain about what you mentioned regarding variable is inactive ?
I want these scenarios below :
- No value is provided for the variable
- A checkbox-type variable is not selected
- Select box-type variable where false selected
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 04:57 AM
The code which I provided checks if the catalog variable is active or inactive. I guess this is not your requirement.
Now that you have explained your requirement let me check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 05:26 AM
Hi @Koyel Guha ,
Check the below code:
template.print("<p></p>Requested items:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while (gr.next()) {
var stage = gr.stage.getDisplayValue();
if (JSUtil.nil(stage))
stage = gr.stage.getChoiceValue();
template.print(gr.number + ": " + gr.cat_item.getDisplayValue() + ", Stage: " + stage + "\n");
template.print(" \n ");
template.print(" More details:\n");
for (key in gr.variables) {
var v = gr.variables[key];
var question = v.getGlideObject().getQuestion();
var label = question.getLabel();
var displayValue = v.getDisplayValue();
if (label && displayValue && displayValue.toLowerCase() !== 'false') {
template.space(4);
template.print(' ' + label + " = " + displayValue + "\n");
}
}
}
Result:
1. here variable "advance" is empty. In email body the above script didn't print "advance"
2. here variable "tt" is not checked & select box "Bu 2" is false & "advance" is empty. In email body the above script didn't print "advance"
If my answer helped you in any way, please mark it as helpful or correct.