- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2022 04:53 AM
I have this mail script to show variables in a approval notification, but this shows a checked hidden variables that i dont need it, how can I hide this variables in the notification?
Thanks!
template.print("<br/>");
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sysapproval.toString());
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
template.space(2);
template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2022 06:42 AM
Then you would need to glide into Item Option table and filter out hidden fields. Please use below script,
template.print("<br/>");
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sysapproval.toString());
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
var grOption=new GlideRecord("item_option_new");
if(grOption.get(vs.get(i).getId())){
if (grOption.hidden==false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
template.space(2);
template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
}
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2022 05:09 AM
A variable being hidden is not something stored in the GlideappVariablePoolQuestionSet. It's in a client script that gets evaluated client-side when the page loads.
Your best option is probably to create a system property called something like "notification.variables.hide" and modify your script to hide any variables whose name appears in that system property.
// at the top of your script, get the vars and make it an array
var hiddenVars = gs.getProperty('notification.variables.hide').split(',');
// in your for loop, update your if statement to check if it's in the array
if (hiddenVars.indexOf(vs.get(i).getLabel()) == -1 && vs.get(i).getLabel()...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2022 05:15 AM
Hi,
There is one OOTB function isVisibleSummay which will resolve your issue. Please try below,
template.print("<br/>");
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sysapproval.toString());
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).isVisibleSummary() && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
template.space(2);
template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
}
}
You can refer this link for more details.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2022 05:29 AM
Hi Abhijit,
I tried this "isVisibleSummary" before and it doesnt work for me, only if I unchecked the "Visible on Summaries" in the variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2022 06:42 AM
Then you would need to glide into Item Option table and filter out hidden fields. Please use below script,
template.print("<br/>");
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sysapproval.toString());
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
var grOption=new GlideRecord("item_option_new");
if(grOption.get(vs.get(i).getId())){
if (grOption.hidden==false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
template.space(2);
template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
}
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP