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

I have a script that will pull fields from the RITM to the REQ notification working. The problem i face now is that i can't seem to figure out how to get the Catalog Item Owner field to show on the RITM form. Any idea?

 

Are you indicating that the Owner field is not showing on the form, or are you indicating you are still having issues. If it is the owner field, you should be able to add it by editing the form. If you are still having issues, please provide what you have built so far so we can troubleshoot.

Update: I have the Catalog Item Owner field now showing on the RITM as per your suggestion of dot walking. The below example shows 'Jairo Ramirez' as the owner.

find_real_file.png

Here is the dictionary entry for that field

find_real_file.png

However, when i call this field in my script, the notification preview gives me 'undefined'

Script:

(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.u_catalog_item_owner+'</span>');
		if(i<rowCount){
			template.print(', ');
		}
		i++;
    }

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

Result

find_real_file.png

If you are do walking does that mean the cat item owner is on the sc_cat_item table? If so you would only need to change one line of code.

gr.u_catalog_item_owner should be gr.cat_item.u_catalog_item_owner.getDisplayValue()

Since this is a reference field we need getDisplayValue() as well otherwise your notification will have the sys_id of the person instead of their name.

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);