Hide False Checkboxes in emails

Tom Thompson
Tera Expert

@Ankur Bawiskar

 

Using the mail Script from  https://www.servicenow.com/community/developer-forum/how-to-include-variable-editor-variables-in-ema...

Name: show_variables 

 

Can you tell me what code I need and where to add it to stop showing all the checkboxes that are not True?

 

Thank you

 

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Tom Thompson 

simply check if value is true or false

what did you start with and where are you stuck?

try this

(function runMailScript(current, template, email, email_action, event) {

// Add your code here

template.print('Variables: <br/>');

var variables = current.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != 'false'){
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@Ankur Bawiskar 

 

this is what I have right now form you helping before..

 

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here

    template.print('<b>Help Center Information: </b><br/>');
   
    var variables = current.variables.getElements();
    for (var i=0;i<variables.length;i++) {
        var question = variables[i].getQuestion();
        var label = "<b>" + question.getLabel() +"</b>";
        var value = question.getDisplayValue();
        if(value!=''){
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        }
    }

})(current, template, email, email_action, event);

View solution in original post

9 REPLIES 9

@Ankur Bawiskar 

 

I added this line to yours

var filled = value != false && value != 'false' && value != undefined && value != '';
if(label != '' && filled){

 

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here

    template.print('<b>Help Center Information: </b><br/>');
   
    var variables = current.variables.getElements();
    for (var i=0;i<variables.length;i++) {
        var question = variables[i].getQuestion();
        var label = "<b>" + question.getLabel() +"</b>";
        var value = question.getDisplayValue();
        var filled = value != false && value != 'false' && value != undefined && value != '';
        if(label != '' && filled){
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        }
    }

})(current, template, email, email_action, event);
 
Seems to work now, any thoughts on that?  am I missing anything?

 

@Tom Thompson 

Looks good now.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you once again for your help!!

@Tom Thompson 

Did you accidentally marked your own response as correct?

Would you mind marking my response as correct?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sorry about that. I corrected..