ServiceNow: How to add Email Recipient to CC and BCC to an outbound email
hello and in this video we're going to be adding someone to a cc and a BCC an outbound email service there [Music] hello and welcome back in this short video we're going to be adding someone to an outbound email we're going to add them as a cc or a BCC because it's not always the case you want to send an email direct to someone perhaps you just want to notify them just to let them know right it could perhaps be um from the watch list or someone's line manager actually that's the scenario we're going to use so we're going to take an incident and we're going to use the existing notification which is when additional comments changes but instead of putting the watch list as a 2 in the email address we're going to put that as a cc and we're going to BCC the caller's line manager so let's hop into the tool and see how it's done so now we've got our incident right so we've got a caller David Miller we're going to send the um incident commented email to him but we're also going to bcc's line manager in this case that's David Liu and we're going to see seeing those in the watch list so that's able tutor and Abraham Lincoln if we just test this out when we add additional comments we add in test it's going to send an email that's going to take a look but it's not going to CC so let's just take a look and see what it says um right out of the box click on this one and we've got here we go we've got Abraham Lincoln David Miller able tutor so these are all recipients of the email but they're not differentiated between Cc or BCS now let's go and do that let's pop into the notification itself click on this internet commenting for ITIL and here you can see these are the recipients right this is what you'd expect to see users groups in fields so we don't want the watch list in here we're going to take that out we do want the caller just save that and now if we click on Advanced View let's have a look see if we can pick a box or something around that allows us to CC or BCC um where you'd expect perhaps one to be in the who will receive section there isn't one so what we're going to need to do is we're going to create something called a mail script that's right we're going to be doing some scripting so let's have a look at how we do that I'm going to come over here I'm going to type in mail Scripts that's what we need to apply um the outbound email the mail script I'm going to create a new one because we're going to CC and BCC that's right uh we're going to call it ccbcc incident example and this is where we're going to start adding our code right so let's handle the BCC first BCC example putting some comments we're going to add email Dot and this is really useful add address so can type can be Cc or BCC this allows three parameters to be passed in in this case it's BCC the next parameter is going to be the person's email address so david.lou.com and then it'll be the person's name okay so that alone um is a bit of script right but we need to apply that script to the Outback notification so what we're going to do is we're just going to save that we've done our mail script we're going to head back over to the notification and add that into the body of email now how do we do that so we need to add in a line of code and that goes in dollar sign curly braces male underscore script because that is what we've just created then we need to get the names we come back we get the name of the mail script add it in there and make sure there's no gaps or click save but what that's going to do is when that sends the email it's going to call that mail script and it's going to run the script that's contained within it in this case it's going to hard code um David Lu into the BCC now that's not great is it because David lose not everyone's mad at a line manager well it could be but let's just pretend he's not so what we need to do is make this a little bit more dynamic so what we can do here is we can start using scripting Powers superpowers we can start using uh adding currents dot caller ID and then we're going to do um manager so we're dot walking we're gonna do get ref record this is actually going to get the record of the manager off the caller record so current is uh incident caller ID is the caller Associated to that incident manager we've got walked to the manager on the user record and now we're getting the whole manager record back why are we doing that so what we can do here is start putting in manager which is our variable on line six dot email then we need the name here so we'll just simply say manager or name save that so now what that'll do is that's going to be more Dynamic so for each incident it's going to pick up the caller ID it's going to grab the manager and it's going to get that record and it's going to put in the manager's email and the manager's name if we wanted to be a bit more watertight we could just say something like why haven't done that something what uh okay we could do something like this what that would then say is if we have a manager then um do this if we don't it's not going to do it and there's lots of different ways you can do that on line seven as well okay so get get valid record we can do that take it out in terms of this so that's going to add in oh there we go um so that's going to add in our BCC so let's just head over give it a quick test before we carry on with the watch list like that head over to our incident type in test post navigate to our email list fresh refresh refresh okay and there we go we look at this one we can see it's now gone out to David Miller um specifically David Miller but wait we can't see any Cc or BCC and this is quite sneaky so what we now need to do is we go to configure form layout we go here and now if you haven't already got them on the form you're going to need to do this we're going copied and blind copied right so we want to move those across I'm going to throw them underneath um recipient whereas recipient recipients down here and we're just going to put them underneath recipients we're gonna okay so now we can see blind copy we've now got David Liu which is exactly what we wanted success let's move on to the watch list so now we head over onto our mail script again so we're going to add in some more code this is going to be a bit more um intensive than the most two lines above and for the purpose of this I'm going to copy in and then we're going to explain it rather than you watching me type because that never goes well pop that in there let's go through it and explain what that actually means for us as well line one we're kind of saying have we got something in the watch list this is all this is doing is saying look let's get the watch list if there's something in it and on line 14 we want to split that by a comma so the watch list is a comma separated sysid list so we want to split it now what we're going to do is go to the user record or the user table sorry and we're going to look for those sys IDs on the user table so sysides are unique identifying records right so we're going to find those records on the user table we're also going to add in this line on 19 which is kind of saying am I able to send notifications to this person that's either yes or no on the user record you might have seen it go and take a look but it says can you send notifications yes we can we're going to add in email has that person got an email address that's all that's doing in line 21 is saying I found the the person by their ID I know I can send them notifications now have they actually got an email address that we can send a notification to then what we do online uh 24 and 26 is we start see seeing that in I'm just going to move these down to make it a bit bit more obvious now what we're doing is in the while loop which is saying hey while we've got all those users in this case it's going to be able and Abraham Lincoln um now I want to CC them in using a similar logic to the that we've seen on line seven look so the only real difference here is BCC or CC so we're putting in there's too many cc's again so we're putting in the person's email address and get display value this time that's the same as what we're doing up here manager.name to be honest best practice or I should have probably done is put manager dot get display value but hey okay but we can do it either way so if we save that we come back over to our incident click test again now we go back over to the emails a quick refresh click on that notification and we can see here look we've got copied in able Abraham Lincoln BCC David Luke so I hope you found the video useful if you if you haven't yet subscribed please consider doing so there's no hard sell if you have subscribed again I apologize as always but thanks for putting up with me and remember smash the Bell icon so you get notified when I upload new videos just like this one till next time I've been Russ this service [Music] [Music]
https://www.youtube.com/watch?v=2k7szQymVBM