GlideappVariablePoolQuestionSet is showing hidden fields in notification

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2016 07:48 AM
I have a notiifcation email script which uses GlideappVariablePoolQuestionSet to display the variables in the request item.Recently i have created a catalog item and while testing i found that hidden fields used as a counter variable are being displayed inside the notification.The script which is written in email script is :
var requestedItem = current.sys_id;
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(requestedItem);
set.load();
var vs = set.getFlatQuestions();
var count = 0;
while (vs.size() > count)
{
if (vs.get(count).getLabel() != '' && vs.get(count).getLabel() != 'null' && vs.get(count).getLabel() != 'asfd' && vs.get(count).getDisplayValue() != '' && vs.get(count).getDisplayValue() != '-- None --' && vs.get(count).getDisplayValue() != ' ')
{
template.print("<tr><td style='border:none;border-bottom:solid #BFBFBF 1.0pt; padding:2.9pt 2.9pt 2.9pt 2.9pt'><p align=right style='margin-bottom:0in;margin-bottom:.0001pt;text-align:right;line-height:normal'><span style='font-family:\"Arial\",sans-serif;'>");
template.print(vs.get(count).getLabel());
template.print("</span></p></td><td style='border:none;border-bottom:solid #BFBFBF 1.0pt;background:#E7EBF9;padding:2.9pt 2.9pt 2.9pt 2.9pt'><p style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'><b>");
if(vs.get(count).getDisplayValue().toString().indexOf('\n') != -1){
var text = vs.get(count).getDisplayValue().toString().split('\n');
var textToPrint='';
for(var k=0; k<text.length; k++){
textToPrint = textToPrint + "<span style='font-family:\"Arial\",sans-serif;color:black;'>" + text[k] + "</span>\n";
}
template.print(textToPrint);
}
else{
template.print("<span style='font-family:\"Arial\",sans-serif;color:black;'>");
template.print(vs.get(count).getDisplayValue());
template.print("</span></b></p></td></tr>");
}
}
count = Math.floor(count + 1);
}
Could anyone hep me to solve this issue.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2016 10:19 AM
Hi Ajai,
We had the same need and these are the steps we followed:-
a. You can create a new variable set as you might have to use this across catalog items
b. Have a variable in the variable set that will store all the active variables on submission of item. To do that you can have an onsubmit client script that will check the table row of all the variables and see if it has a style of display none. If it is not it will add the item to an array. And then once it has looped through the variable sequence it will convert the array to string and store it in the variable declared in variable set.
c. Then trigger a parallel workflow when the catalog item gets submitted.
d. In that new workflow, set an option flag (declared as a new column in variable ownership table ) to true for the variables that are found in the variable declared in the variable set
e. The option flag will then be true only for the columns that were active and not hidden.
f. In your notification check for this flag and then render them.
g. You can also, add the same flag check in the variable summary so that only concerned variables show up.
Hope the approach helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2016 12:31 AM
Thanks for your reply.
The resolution which you have mentioned is by changing the rendering of fields in the notification.
But I actually wanted to know, based on what the fields are taken from request item using GlideappVariablePoolQuestionSet.
I have many fields in that Catalog item. Eventhough many fields are hidden by using Ui policies only these counter fields are being displayed in the notification. So Could anyone help me to understand this ??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2016 04:36 AM
For this I have done a small workaround which seems to be working perfectly.
As the fields without values are not being displayed in the notification.I wrote an onsubmit script which will clear my counter variables on submit .So these variables are not displayed in the notification now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2016 07:33 AM
Ajai,
I do this for sc_req_item notifications, sc_task notifications, and sysapproval_approver notifications. The only thing that needs to change in the script is the value passed to set.setRequestID. This will only print variables with values. Caution, if you hide variables and do not clear the value, they will appear in the notification. To get around this you can add to the if statement to not display them. For example, I don't display the Urgency field as I display this later in the notification. This method works very well and displays the variables in the proper order without having to worry about sorting. I have a requirement to display everything in notifications in a certain font which is why you see the style defined.
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.request_item);
set.load();
var q = set.getFlatQuestions();
var iter = q.iterator();
while (iter.hasNext()) {
var item = iter.next();
if (item.getLabel() != 'null' && item.getLabel() != 'Urgency' && item.getDisplayValue() != '' && item.getDisplayValue() != 'None' && item.getDisplayValue() != 'null')
template.print("<p><p style='font-family: calibri; font-size: 14.5px'><b>" + item.getLabel() + "</b> - " + item.getDisplayValue() + "</p>");
}