How to get multiple display values from a list collector variable in variableset onto a notification

sowmya28
Tera Contributor

@Ankur Bawiskar 

 

How to get multiple display values from a list collector variable in a multi-row variable set onto a approver notification. Please help me on this. Thanks in advance.

 

I haven taken below code as reference.

 

For that sysId you need to query the table being referred by that variable and then get the display value

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

    
    var record = new GlideRecord('sc_req_item');
    var sysCurrentRecordSysId = current.sysapproval;
    record.addQuery('sys_id', sysCurrentRecordSysId);
    record.query();
    if (record.next()) {
        var obj = JSON.parse(record.variables.request_information); //update with your variable set name
        for(var i=0; i<obj.length; i++) {

            var rec = new GlideRecord('tableReferredBySystemName');
            rec.get(obj[i].system_name);

            var rec1 = new GlideRecord('tableReferredByProfileName');
            rec1.get(obj[i].profile_name);

            template.print('<br/>' + 'System: ' + rec.getDisplayValue()); 
            template.print('<br/>' + 'Profile: ' + rec1.getDisplayValue());
            template.print('<br/>' + 'Approver: ' + obj[i].aprovador_do_perfil);
        }
    }
}

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

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@sowmya28 

try this

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
										   /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
										   /* Optional GlideRecord */ event) {


	var record = new GlideRecord('sc_req_item');
	var sysCurrentRecordSysId = current.sysapproval;
	record.addQuery('sys_id', sysCurrentRecordSysId);
	record.query();
	if (record.next()) {

		var systemNameArray = [];
		var profileNameArray = [];
		var approverArray = [];

		var obj = JSON.parse(record.variables.request_information); //update with your variable set name
		for(var i=0; i<obj.length; i++) {

			var rec = new GlideRecord('tableReferredBySystemName');
			rec.get(obj[i].system_name);

			systemNameArray.push(rec.getDisplayValue());

			var rec1 = new GlideRecord('tableReferredByProfileName');
			rec1.get(obj[i].profile_name);

			profileNameArray.push(rec1.getDisplayValue());

			approverArray.push( obj[i].aprovador_do_perfil.toString());

		}
		template.print('<br/>' + 'System: ' + systemNameArray.toString()); 
		template.print('<br/>' + 'Profile: ' + profileNameArray.toString());
		template.print('<br/>' + 'Approver: ' + approverArray.toString());

	}
}
)(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 

 

I tried below code as you suggested.

 

var record = new GlideRecord('sc_req_item');
	var sysCurrentRecordSysId = current.sysapproval;
	record.addQuery('sys_id', sysCurrentRecordSysId);
	record.query();
	while(record.next()) {

		var colorArray = [];
		
		var obj = JSON.parse(record.variables.color_information); //update with your variable set name
		for(var i=0; i<obj.length; i++) {

			var rec = new GlideRecord('u_demo');
			rec.get(obj[i].color_name);
			colorArray.push(rec.getDisplayValue());
		}
		template.print('<br/>' + 'color: ' + colorArray.toString()); 

 

 

If I select single color value, then it is being displayed in the notification.

If I select multiple color values, then it is displaying as blank

 

Actually my list collector variable is reference to a custom table(u_demo) and has a reference qualifier(javascript&colon;'u_color=true');

 

Please help me on this issue.