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.

Email notification with only selected options from select box

New user1212
Tera Contributor

Hi,
I have a problem with the email that asks for approval.
Item has 3 Select boxes and depending on the first one, the remaining 2 appear.
I would like the notification to show only what the user has selected, not everything.
How can I achieve this?

Newuser1212_0-1721130238244.png

Newuser1212_1-1721130271968.png

 

 

2 REPLIES 2

Brian Lancaster
Kilo Patron

User an email notification email script. Below is a code and can be used on multiple notifications depending on the table triggering the notification including approval.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
	var item_sys_id;
	var tableName = current.getTableName();		
	if(tableName == 'sysapproval_approver'){
		item_sys_id = current.sysapproval;		
	} else if (tableName == 'sc_task'){
		item_sys_id = current.request_item.sys_id;
	} else if(tableName == 'sc_req_item'){
		item_sys_id = current.sys_id; 
	} else{
		item_sys_id ='';
	}
	//gs.log("SYS ID : "+item_sys_id);
    var item = new GlideRecord("sc_req_item");
    item.addQuery("sys_id", item_sys_id);
    item.query();
    while (item.next()) {
        template.print("<div style='font-size:12pt;font-family:Arial, Helvetica, sans-serif;'><span><b>Options</b>:</span><br />");
        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() != '') { //This displays all of the variables (answered/unanswered)
                            
                var val = vs.get(i).getDisplayValue();
                if (val != '') {
					template.space(4);
                    template.print(vs.get(i).getLabel() + " : " + val + "<br />");
                }
            }
        }
        template.print("</div>");
    }

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

 

some email template is used here:

Newuser1212_0-1721145004742.png

and when I check what is in the 'requested_items_summary_with_options' place, there is such a script. Should I change anything here?

Newuser1212_1-1721145085362.png