Catalog Item Owner on Request notification

Russell Abbott
Kilo Sage

I have a requirement to include in the email notification for a Request closure, the Catalog Item Owner for the associate RITM.

In the email notification i tried the following

"If you feel that your Request was closed improperly, you can escalate to ${variables.cat_item.owner.name} at ${variables.cat_item.owner.phone}" but these values do not seem to bring anything over, blank.

Does anyone have any insight here? I'm aware that some Requests may have multiple RITM's, so i don't know how that would be handled. The majority of our Requests have one RITM.

1 ACCEPTED SOLUTION

Rather than trying to access the custom field you created, you can access through the cat_item field. I recreated accessing the name and phone from the user record that is on the Catalog Item record. To reproduce, get the sys_id of a Request record, then run the following:

var reqGr = new GlideRecord('sc_request');
reqGr.get('sys_id_of_request_record'); //place the sys_id of the current request record
var itmGr = new GlideRecord('sc_req_item');
itmGr.addQuery('request', reqGr.sys_id);
itmGr.setLimit(1);
itmGr.query();
if(itmGr.next()) {
    gs.log(itmGr.cat_item.owner.name); //Here is where you get the owner name
    gs.log(itmGr.cat_item.owner.phone); //Here is where you get the owner phone
}

Taking what you indicated there are pieces that are not necessary, so I refactored the mail_script to incorporate the code from above:

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

    var itmGr = new GlideRecord('sc_req_item');
    itmGr.addQuery('request', reqGr.sys_id);
    itmGr.query();
    var rowCount = itmGr.getRowCount();
    var ownerName = '';
    var ownerPhone = '';
    var printText = '';
    while (itmGr.next()) {
        ownerName += itmGr.cat_item.owner.name;
        ownerPhone += itmGr.cat_item.owner.phone;
        printText += itmGr.number + ': ' + ownerName + ' at ' + ownerPhone;
    }
    template.print('<span style="font-family: Montserrat;font-size: 12pt;">' + printText +'</span>');
})(current, template, email, email_action, event);

View solution in original post

11 REPLIES 11

This worked, thank you so much!

Would this work? I haven't yet pulled the 'owner' variable from the Catalog Item to the RITM form yet but i can do.

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

    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('request', current.sys_id);
    gr.query();
	var i=1;
	var rowCount=gr.getRowCount();
    while (gr.next()) {
        template.print('<span style="font-family: Montserrat;font-size: 12pt;">'+gr.owner+'</span>');
		if(i<rowCount){
			template.print(', ');
		}
		i++;
    }

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