Create a Email Script: getAllVariables as example below and call in notification like ${mail_script:getAllVariables}

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

    var html_details = "<table><tr><th style='text-align: left;'>Variable Name</th><th style='text-align: left;'>Variable Value</th></tr>";
    template.print("<b>Summary of Requested items:\n</b>");
    var item = new GlideRecord("sc_req_item");
    if (item.get(current.sys_id)) {
        template.print(item.number + ": " + item.cat_item.getDisplayValue() + "\n");
        var keys = new Array();
        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).getDisplayValue() != '') {
                html_details = html_details + "<tr><td style='text-align: left;'>" + vs.get(i).getLabel() + "</td><td style='text-align: left;'>" + vs.get(i).getDisplayValue() + "</th></td></tr>";
                //template.space(4); template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
            }
        }
        html_details = html_details + variableSet(item);
    }
    html_details = html_details + '<table>';
    template.print(html_details);

    function variableSet(item) {
		var temp='';
        var itemName = item.cat_item;
        var grSet = new GlideRecord('io_set_item');
        grSet.addQuery('sc_cat_item', itemName);
		grSet.addEncodedQuery('variable_set.type=one_to_many');
        grSet.orderBy('order');
        grSet.query();
        while (grSet.next()) {
			var title=grSet.variable_set.title;
			var name=grSet.variable_set.internal_name;
            var mrvs = item.variables[name];
			var rowCount = mrvs.getRowCount();
			var isPrint=false;
			var childSet="";
			for(var i=0; i<rowCount;i++){
				var count=i+1;
				isPrint=true;
				var row = mrvs.getRow(i);
				var obj=JSON.parse(row);
				for(var key in obj){
					childSet=childSet+"<tr><td  style='text-align: left;'>Row-"+count+"</td><td style='text-align: left;'>"+key+"</td><td style='text-align: left;'>"+obj[key]+"</td></tr>";
				}
			}
			if(isPrint ==true){
			temp = temp+"<tr><td style='text-align: left;' colspan='2'><b>"+title+ "</b></td></td></tr>";
			temp=temp+childSet;
			}
        }
        return temp;
    }
})(current, template, email, email_action, event);

Total Views: 1308

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *