- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 02:44 AM
Hi,
We have catalog form and it has checkbox variables in it.
user while filling the form, he will select the required checkboxes, some of the checkboxes will remain un-checked.
Here requirement is to display the only checkbox variables which are checked or selected on the email notification template.
If user will not select any checkbox variable on the form, then it should not be displayed on the email notification template.
please help me how can I achieve this.
Thank you.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 03:39 AM
Hi Ankur,
This is the code I have have been using in email script, But none of the check box variables are displaying in email notification.. even though they are true. please correct me if anything wrong this code.
Thank you.
template.print('<p>Roles that Should be Assigned to the Requested User:<br />');
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sysapproval);
item.query();
while(item.next()) {
var keys = [];
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() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue().toString() != 'false') {
if(vs.get(i).getLabel() != "Requested for:" && vs.get(i).getLabel() != "Opened by:" && vs.get(i).getLabel() != "Approval for")
htmlContent += '<tr><td class="nameValue" width="30%">' + vs.get(i).getLabel() + ':<br><br></td><td width="60%" class="body_content" valign="top">' + vs.get(i).getDisplayValue() +'<br><br></td></tr>';
}
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br />");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 05:14 AM
Hi Ankur,
I have tried your code, but none of the check box variables are displaying..
After that I have tried the below code.. and it is working, But here issue I am facing is in the below screenshot, YELLOW highlighted variables are displaying which is not required.
Those yellow highlighted variables are displaying because they have some value in it... so please help me how can I display only variables which are not highlighted.
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id.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(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br/>");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 06:10 AM
Hi Harish,
In the question you have mentioned that you want to print variables where checkbox is selected i.e. value as true.
So the code is working fine right i.e it is showing variables with true value only
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 06:14 AM
yes Ankur, it is displaying the checkbox variables with value as true, but it is also displaying the variables other than checkbox variable as well.. that is the issue.
we want to print only checkbox Variables with it's label
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 06:18 AM
Hi Harish,
Following script should work. this will print only those variables where value is true. highlighted in bold
- var set = new GlideappVariablePoolQuestionSet();
- set.setRequestID(current.sys_id.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() == 'true' ) {
- template.space(4);
- template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br/>");
- }
- }
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 05:10 AM
Hi Harish,
Any update on this?
Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader