Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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
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

@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);

@Tom Thompson 

please try the updated script I shared above

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

@Ankur Bawiskar 

 

Sorry that did not work, it now shows all false values.

TomThompson_0-1706708247696.png