Email script to display message based on request catalog item

RF
Kilo Contributor

 

Hi everyone.

I have an email approval notification and I want it to display a specific message based on the catalog item. So basically, if the approval is for a requested item, and the requested item is from a specific catalog item, I want the notification to display a message.

I'm not experienced in scripting, so I am facing some issues on getting a value from an extended table. In this case, I'm trying to reach sysapproval_approver.sysapproval (reference to task table) > sc_req_item > cat_item.

Thanks in advance!

1 ACCEPTED SOLUTION

Tyler Hoge - Gl
Tera Guru

If you want to include this in the same notification as all the other approval notifications you will need to do a query for the approval record. Since the approving field is normally a document id field and not an actual reference field. 

 

 

var gr = new GlideRecord('sc_req_item');

gr.get(current.document_id);

if(gr.cat_item == "your cat item sys_id"){

   template.print("additional message you want to send");

}

 

If you also have a hidden reference field which some people have in their instance, you will be able to dot walk to the actual request item without doing a query. if this field is available to you I would recommend creating a specific notification for that item and filtering it out of the general one. to do that in the condition you will need to scroll down to the bottom of the list and click "show related fields" this will show you the fields that you can dot walk into. Here is an example Dot Walk Conditions.

 

View solution in original post

4 REPLIES 4

Mike Allen
Mega Sage

I always copy the existing notification, making one 'ITEM is [my_cat_item]' and one 'ITEM is not [my_cat_item]', and change the verbiage on the one that I want to change.

 

It is simple, and there is probably a more complex way to do it dynamically, but that is what I do and it works for me.

RF
Kilo Contributor

Thanks Mike! I was going to go for this method if I couldn't figure out how to do it dynamically.

Tyler Hoge - Gl
Tera Guru

If you want to include this in the same notification as all the other approval notifications you will need to do a query for the approval record. Since the approving field is normally a document id field and not an actual reference field. 

 

 

var gr = new GlideRecord('sc_req_item');

gr.get(current.document_id);

if(gr.cat_item == "your cat item sys_id"){

   template.print("additional message you want to send");

}

 

If you also have a hidden reference field which some people have in their instance, you will be able to dot walk to the actual request item without doing a query. if this field is available to you I would recommend creating a specific notification for that item and filtering it out of the general one. to do that in the condition you will need to scroll down to the bottom of the list and click "show related fields" this will show you the fields that you can dot walk into. Here is an example Dot Walk Conditions.

 

Thanks Tyler! This did it for me. Didn't think it was that simple, I was over complicating things.