Including the Same Attachment to a ServiceNow Notification Every Time it Sends
in this video we're going to be looking at adding the same attachment to a notification every time it sends so I have a article up on my blog uh with the instructions on how to do this and this video is basically just going to follow uh these instructions so let's head over to service now and the so sometimes you get a requirement where you need to send the same attachment every time uh and notifications sends if we go to the notifications and I have one up here a sample uh you'll notice that out of the box there is a field here include attachments and if you Mouse over the label you get the message send all attachments from the triggering record as email attachments so uh checking this we'll take uh any attachments that are attached to the incident record and include them in the email that goes out uh but sometimes we just have a single attachment a form or something like that that we need to send out uh every time and so I I've seen uh and I was tempted to do this myself uh I've seen folks attach a uh put an attachment on to here and then wonder why the heck it's not going out when when the notification sends uh because out of the box putting an attachment on this record on the notification record doesn't do anything so what we're going to look at is um adding this checkbox here include attachments from this notification record uh in order to include any attachments that might be attached to this record to this notification record so the first step is to Simply create a field on the notification record uh on the notification table rather and uh it's a true false field uh where you check the box uh I usually add it to the default uh not to the default view to the advanced view so when you first go in here you get the default view right and that uh kind of simplifies things you don't see a lot of the fields uh so you have to do Advanced View and then stick your uh true false uh field over here now once that's done you head over to the this email log table and you go in here and you go to the uh business rules and you create a new business rule you can call it include attachment from this notif record or anything you want it's a after business rule so again you have to actually yeah you have to click the advanced in order to see some of these options so it's a when it's an after business rule because we want it after this log a record is created uh it's done on insert only and then in the filter conditions we're going to go and look for that field in the notification so this table and let's just back up a second this table is the table that links the whoops this table links go back here links the and S I created because I already did a few test so it links the email um with the notification and possibly the event as well uh so uh for these right because this notification that I created is triggered from a record update um but it could be triggered from a flow it doesn't really matter um but anyway so this table is what links those two things together so you know that uh this email is from this notification because if you go on the CIS email table uh there's nothing to indicate which notification that email is from so the only way to link the two is this uh CIS email log table okay so getting back to our business rule the only condition on this business rule is that the include attachments from this notification record is true right so in order to get that field you have to uh so if we let's just get rid of this and do it again if we go in here right so we have there's only a few fields in this table and the most important ones are notification and email so in the notification we have to do uh show related fields then we go notification notification fields and then we can see that field that we created in the notification include attachments from this notification record and so that when that's true and this is inserting uh after the insert it will run what we have here in the script and I have the script outlined in the article here uh you can just copy pasta right in there so let's just take a look at it see what it's doing uh so what we're doing here is we are uh creating a new instance of glide's attachment and with Glides his attachments we're saying hey go get the attachments from that notification record right so whatever I attach to the notification record itself it's going to go get that and stick it in this uh atgr variable so this is a um a glad record object of potentially several uh Glide records so now I just Loop through that uh that grouping of attachments and here I fire up a Glide record on the CIS email attachment table so this is and we'll take a look at this in a minute when we do a test this is the table that stores uh the attachments that get uh attached to emails uh to out outgoing actually I think to ingoing in inbound emails as well I'm not sure about that I to but definitely to outbound emails uh so I'm just initializing it and I am saying uh Hey for this first attachment uh the attachment field set it to that and the email is the email from the uh CIS email log table uh the source is notification the content disposition is a attachment and the file name is the file name of the attachment and we'll go look at this table in a minute uh when we're when we launch the test so basically it just launches it just uh creates a record for each attachment um that's uh attached to the notification uh and that's it so then you can go create a notification and I did that here and on your notification you can say uh include attachments from this notification record set that to true for this test purposes I just put a uh notification on the incident table and it's going to fire basically anytime an incident is updated again this just for testing purposes um but it it doesn't matter how the record is triggered everything else about the notification is exactly the same then you just attach some uh some document to the notification here I have a uh I think it's a Christmas photo of my family something like that put that on there and uh let's fire one up let's fire an incident off and see what happens so we'll go to incidents and take any one of these and we'll just change the category okay then I'm going to head over to the I'll just leave it in another browser tab I'm going to go over to the um cemail table and we can see let's see if this is it 2304 that's me uh so this is the the notification that went out and if I scroll down to the bottom here I get the related list the email attachments related list so this is the CIS email attachments uh table we were looking at earlier and here I can see that that record is attached and let's actually open this record so we can see the attachment is here this is the file that was attached to the a notification record and then the file name just gets the file name from that attach M uh the email and these are the values that we set in that business rule uh it's connected to the email that we saw right that was the parent we were just in source is notification I don't know what else is oh yeah see inbound email is the other one so uh this table is also used for inbound emails and then content disposition is attachment right there's also inline of course that that's for uh if you have like an HTML email uh action reason is nothing and action is uh right so this is for inbound what uh what you do with the attachments so this is an outbound attachment um so that's it it's attached to this record this is a PDI so email is not turned on we can't actually see that but if you're on an instance uh that has email enabled you will be able to uh you should be able to receive this email and see that the attachment is in there so again I will link to my uh to the blog article where you can just uh copy paste the script and the business rule and uh you should be up and running that's how to send a generic attachment uh with every every time a notification sends in service now
https://www.youtube.com/watch?v=kN6Vct7-YKA