Don't show Check box variables with value false in email notification

RudhraKAM
Tera Guru

We have a notification on sysapproval ,when a request is created we will be sending all the variables on catalog item but we have couple of items where we have 50 checkboxes , If user select only 1 check box  in the notification for approval all other 50 fields are displayed , is there a way to show only the selected checkbox instead of showing all check box ?

 

below is the mail script 

 

var classtype = current.sysapproval.sys_class_name;
if (classtype == 'sc_req_item') {
	
	var gr = new GlideRecord('sc_req_item');
	if (gr.get('sys_id', current.sysapproval)) {
		template.print("<b>Title</b>: " + gr.short_description + "<br />");
		template.print("<b>Requested for</b>: " + gr.request.requested_for.getDisplayValue() + "<br />");
		
		template.print("<b>Options:</b><br />");
		
		var varown = new GlideRecord('sc_item_option_mtom');
		varown.addQuery("request_item", gr.sys_id.toString());
		varown.query();
		while (varown.next()){
			var visible = varown.sc_item_option.item_option_new.visible_summary;
			var question = GlideappQuestion.getQuestion(varown.sc_item_option.item_option_new);
			question.setValue(varown.sc_item_option.value);
			if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true){
				template.space(4);
				template.print('     ' +  question.getLabel() + " = " + question.getDisplayValue() + "\n");
			}
		}
		
		
	}
} else {
	template.print("<p></p>Requested items:\n");
	
			var gr = new GlideRecord("sc_req_item");
		gr.addQuery("request", current.sysapproval.sys_id);
		gr.query();
		while(gr.next()) {
			template.print("<b>Title</b>: " + gr.short_description + "<br />");
			template.print("<b>Requested for</b>: " + gr.request.requested_for.getDisplayValue() + "<br />");
			
			template.print("<b>Options:</b><br />");
			
			var varown = new GlideRecord('sc_item_option_mtom');
			varown.addQuery("request_item", gr.sys_id.toString());
			varown.query();
			while (varown.next()){
				var visible = varown.sc_item_option.item_option_new.visible_summary;
				var question = GlideappQuestion.getQuestion(varown.sc_item_option.item_option_new);
				question.setValue(varown.sc_item_option.value);
				if (question.getLabel() != "" && question.getDisplayValue() != "" && visible == true){
					template.space(4);
					template.print('     ' +  question.getLabel() + " = " + question.getDisplayValue() + "\n");
				}
			}
			
		}
	}

 

4 REPLIES 4

amaradiswamy
Kilo Sage

Hi @RudhraKAM 

 

Replace your logic where you are querying sc_item_option_mtom with below

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

var ritmSysId = current.sys_id;
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
var vs = set.getFlatQuestions();

for (var i=0; i < vs.size(); i++) {

var label = vs.get(i).getLabel();

var variableName = vs.get(i).getName();

var variableValue = vs.get(i).getDisplayValue();

if(label !='' && variableName !='' && variableValue.toString() == 'true')

template.print(label + ' : ' + variableValue);

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

var classtype = current.sysapproval.sys_class_name;
if (classtype == 'sc_req_item') {

    var gr = new GlideRecord('sc_req_item');
    if (gr.get('sys_id', current.sysapproval)) {
        template.print("<b>Title</b>: " + gr.short_description + "<br />");
        template.print("<b>Requested for</b>: " + gr.request.requested_for.getDisplayValue() + "<br />");

        template.print("<b>Options:</b><br />");

        var varown = new GlideRecord('sc_item_option_mtom');
        varown.addQuery("request_item", gr.sys_id.toString());
        varown.query();
        while (varown.next()) {
            var visible = varown.sc_item_option.item_option_new.visible_summary;
            var question = GlideappQuestion.getQuestion(varown.sc_item_option.item_option_new);
            question.setValue(varown.sc_item_option.value);
            if (question.getDisplayValue() != false && question.getDisplayValue() != "" && visible == true) {
                template.space(4);
                template.print('     ' + question.getLabel() + " = " + question.getDisplayValue() + "\n");
            }
        }


    }
} else {
    template.print("<p></p>Requested items:\n");

    var gr = new GlideRecord("sc_req_item");
    gr.addQuery("request", current.sysapproval.sys_id);
    gr.query();
    while (gr.next()) {
        template.print("<b>Title</b>: " + gr.short_description + "<br />");
        template.print("<b>Requested for</b>: " + gr.request.requested_for.getDisplayValue() + "<br />");

        template.print("<b>Options:</b><br />");

        // 			var varown = new GlideRecord('sc_item_option_mtom');
        // 			varown.addQuery("request_item", gr.sys_id.toString());
        // 			varown.query();
        // 			while (varown.next()){
        // 				var visible = varown.sc_item_option.item_option_new.visible_summary;
        // 				var question = GlideappQuestion.getQuestion(varown.sc_item_option.item_option_new);
        // 				question.setValue(varown.sc_item_option.value);
        // if (question.getDisplayValue() != false && question.getDisplayValue() != "" && visible == true ){
        // 					template.space(4);
        // 					template.print('     ' +  question.getLabel() + " = " + question.getDisplayValue() + "\n");
        // 				}
        // 			}

        var ritmSysId = current.sys_id;
        var set = new GlideappVariablePoolQuestionSet();
        set.setRequestID(ritmSysId);
        set.load();
        var vs = set.getFlatQuestions();

        for (var i = 0; i < vs.size(); i++) {

            var label = vs.get(i).getLabel();

            var variableName = vs.get(i).getName();

            var variableValue = vs.get(i).getDisplayValue();

            if (label != '' && variableName != '' && variableValue.toString() == 'true')

                template.print(label + ' : ' + variableValue);

        }
    }}

 

 

Updated as above but still not working

Please try with the below:

 

 var classtype = current.sysapproval.sys_class_name;
    if (classtype == 'sc_req_item') {
template.print("<b>Title</b>: " + current.sysapproval.short_description + "<br />");
		template.print("<b>Requested for</b>: " + current.sysapproval.request.requested_for.getDisplayValue() + "<br />");
		
		template.print("<b>Options:</b><br />");
        var ritmSysId = current.sys_id;
        var set = new GlideappVariablePoolQuestionSet();
        set.setRequestID(ritmSysId);
        set.load();
        var vs = set.getFlatQuestions();

        for (var i = 0; i < vs.size(); i++) {

            var label = vs.get(i).getLabel();

            var variableName = vs.get(i).getName();

            var variableValue = vs.get(i).getDisplayValue();

            if (label != '' && variableName != '' && variableValue.toString() != 'false')

                template.print(label + ' : ' + variableValue+'<br />');
        }


    } else {
        template.print("<p></p>Requested items:\n");
 template.print("<b>Title</b>: " + current.sysapproval.short_description + "<br />");
            template.print("<b>Requested for</b>: " + current.sysapproval.requested_for.getDisplayValue() + "<br />");

            template.print("<b>Options:</b><br />");
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("request", current.getValue('sysapproval'));
        gr.query();
        while (gr.next()) {
            var ritmSysId = gr.getValue('sys_id');
            var set = new GlideappVariablePoolQuestionSet();
            set.setRequestID(ritmSysId);
            set.load();
			template.print('Inside while')
            var vs = set.getFlatQuestions();

            for (var i = 0; i < vs.size(); i++) {

                var label = vs.get(i).getLabel();

                var variableName = vs.get(i).getName();

                var variableValue = vs.get(i).getDisplayValue();

                if (label != '' && variableName != '' && variableValue.toString() != 'false')

                    template.print(label + ' : ' + variableValue+'<br />');
            }
           

            

        }
    }

RudhraKAM
Tera Guru

can some one help me with this ?