ServiceNow Notification Email Scripts : Your Ultimate Tutorial for adding ServiceNow email CC/BCC
it's not a game hi all welcome back okay to our Channel today we have an exciting topic to discuss that will make your life easier when it comes to sending emails with servicenow we'll be diving into the world of mail script today okay and showing how you can how you can use manuscript to set CC and PCC response so now You Must Be Wondering right what exactly is service number script well let me break it down to you service now mail script is a powerful tool within servicenow platform that allows you to play around email related tasks okay such as sending receiving emails passing email content and Trigger action based on the email events it's a game changer streamlining your email workflow you can also add CC BCC app also you can create a body okay dynamically from the script over the in the image group so without first wasting further time okay let's get started so as you can see on my screen this is my personal development instance and currently I'm on uttar release okay my personal development instance um and uh in order to get started right we need some Target table on on that particular Target table we need submit notification so as always we'll be targeting to the incident table only because that's our favorite table so we'll go to the incident and look for some notification which we can play around right so I will just go ahead and I will just configure configure and let's go to the notifications so let's we have a notification out of the box called incident commented for itl let's see what exactly is doing so basically this notification is getting triggered if we go to when to send um getting triggered to whenever the additional command is comments is added okay on the incident and who is received are the current dates only to the caller so whenever the caller of the incident gets this notification perfectly fine okay so now let's get started okay so whenever we add a notification now uh commit to additional comment to this notification to the incident this notification will get triggered let's give it a try so I will just go to incident dot last let's find our first Target record so let's go with this and let's it has system advertised let's make it able today start us able tutor okay because caller is must right and we will give additional comment as test one and we will save it out so now you must be thinking how we can verify whether the email got triggered or not so it's pretty easy if you go to the filter Navigator and search for emails so under system logs you will be finding the model called image if you go over here you can see the last trigger notification oh return trigger why refresh it out just now okay perfect and you can see we have the recipient as this my email ID okay which I configure for Apple tutor and the blind copied and copied is empty if you are unable to see this Fields plant copied and copied on this email record you have to just configure the form and get the fields on the form because out of the box these are not present on the form so let's guess let's try to put some information on this okay so for this as I stated that we have to create a mail script or we can create a mail script so what you have to do go to filter Navigator type email script in my script and you will get node under system notification image you have notification email script so let's create one so I'll give new we have to give you the name let's give it a name as Tech no mock emails okay and then you can write start writing the script so as a part of this mail script you have multiple input parameters which you can play around run mail script okay now has this is a function which has current will be the current object for instance we we are calling it from incident table right so instead of current object will be over here then we have template we have email and so on right but we'll be focusing on ccnbcc for today so let's work on the first scenario okay let's see see some hard-coded user okay so what I will be doing uh what is the Syntax for it this is pretty easy you have to do email dot add address okay and you have to use CC and BCC is the two right so we did copied see then the next attribute we have to give is the email ID on which you have to you want to add to CC so I will just give techno mog123 which is my official immunity and gmail.com I know it's quite weird and then you have to provide the name of that recipient so I can give any name you can give you can give technomanc okay so this is good and we will save this out now there should be one question coming to your mind that we have created a mail script there is no reference to notification from this manuscript right how this will get related to each other right good question so what you have to do you have to call this you have to configure this manuscript on the notification so we will go to the notification okay and we will see how we can call the image script from the notification so you can go to what it will contain okay there will be email body right over there you can simply the syntax is dollar curly braces you have to type mail underscore script colon and the script name which is techno monkey viewing that's it you're done calling the calling it out okay so let's save this out and let's give it a try so we'll go back I know I play a lot around this tabs right but I guess you will get the gist of what I am doing right so I will just add a comment again I will give test two and this time we are expecting that it should get to call or email plus the email ID which we have configured okay so I will do Ctrl s if we go to image now created on today so it must have created a record yeah it created and now we can see we got copied also perfect right and it's pretty easy also pretty nice right now you must be thinking we have given the hardcore values right okay can't we make it Dynamic definitely we can make it Dynamic so let's make it Dynamic so the first step what we can do is like we will go to the image script yeah and let's try to send the notification to chorus manager because it makes sense also right so what I will do I will just give variable column manager equal to as I've told that we have access to current object rights it will be current Dot caller underscore ID caller ID underscore it will reference to the caller object right use object we have to go to the manager for it so it's manager and Dot edger and managers we want email ID right we don't want entire objects so we can go to email and that's it will give the email ID for that manager and then we can replace this out this technomancing okay which is really I don't like this viewing my own Melody and we can give color managerial that's it done and now whenever an incident is called This Record should send the notification to its manage a female ID okay so let's first verify what what email ID should go over there so I will go over here incident so who is a student manager sorry yeah I got it was able to test manager it's Abraham Lincoln okay so the mayor should go to Abraham Lincoln okay if it has email let's verify that also so Abraham Lincoln has emailed my email that's nice everywhere I can see my emails okay so let's ADD test three with time make CC okay Ctrl s the record got saved now oh I think I'm popped because I've lost the I get a bar and over here we have to go to history emails created today last email just now okay why is it the last one just now let's go back to the incident what went wrong let's verify notification once um notification this looks good something got missed over there to the image script let's see it's current dot caller undiscuit ID dot manager dot email [Music] it looks good What happened to the it looks good for me okay let's go back and try it one more time test 4 controlled as hmm now it went to Abraham Lincoln email ID also I don't know what happened last time okay so we can see CC and BCC is there now let's look into some tough scenario okay so for instance if you want to BCC the entire watch list right can you do it with the mail script definitely you can do it with the main script how let's work on that so what you can do we will go to email script only the technology script and here that's all at that logic okay so let's make some validation so first of all we have to see if the is there anything in the watch list or not so if not current Dot watch in this good list dot nil if it's not nil then only we'll proceed with this right else we don't want to do anything right then let's get the as you know it will be a comma separated ID is over there right so we will give variable watch list users users equal to I will just copy from here current dot washed list [Music] dot as you know it's a comma separator right so we can simply do split with comma right so we will get array out of it right so you can simply use a you can give it array okay split will give you array as a output now we can simply do the Glide record okay iterate through this list address through this array right so we can do variable use GI user is that equal to new Glide record and it will be to fuse the table so it will be say send this code user sys user and in this we'll be adding um what's loading I can type faster than that see a user Dot add query and that query will have societies right so it says underscore ID is is you can you watch this user array now we can add some more validations right which are required on the user table okay you will be asking what validation right what if user is in inactive do you want to send the notification to him no right so let's add those validation also so what we can do I will open some record out and I have as an utility installed in my browser right so I can do a couple of things so first is like it should not be activist 2 should be true okay apart from that there is a there is a check box right and let's add this only for now okay I will just go to act equal to true copy query and we can go back we can go back to the script did I lost the script hopefully no so yeah we have the script and I can also do giuser Dot add encoded query you can also do a lot of things around it right because there is a notification flag if it's true or not you can check okay it's the choice value okay also you can check if email ID is empty or not it should not be empty right and so on but I will just for time being I will just give resist like this and then so you can do GI user dot query if any user exists okay so for that we can use while loop while GI user Dot next what we have to do we have to add it to the CC right so what is the Syntax for BCC now let's try for BCC so you can simply copy this out and I will paste it out to the shift tab and instead of CC you can simply do BCC okay BCC whatever the email ID over here so it will be a user dot email and what is the name for it it will be gr user dot get display name works for you right so I think it's configured now you can save it out and let's try to add some couple of people to the to the work nodes so I'll go to the history let's open the incident record so let's add couple of people not myself okay my bad and let's we can just ask and I will add four or five people I'm not pretty sure why active or not okay and I can see save this out first and then we will add the additional commands so we have this many users now the recipient should be the caller the BC the CC should be the manager and pvcc should be the this watch this people right so test final and if I save this out if I go to history from history if I go to emails that image created today created eight minute ago it went up only let's go to sorry let's go to incident once so let's add command okay uh to this particular so let's do it test 11 and if I save this out okay let's go to the image and see if we got something over there so if I go image create run today you can see the record and here we can see now we have recipient line copy and CC also so this is how you can use the image script okay uh to add CC BCC to your to your image okay to your email and extend your page of the image right okay so I hope you like this video okay if you liked it out please subscribe to my channel and press the Bell icon so that you will get notified okay whenever I am adding new videos till then stay safe stay happy and have a nice day ahead thank you
https://www.youtube.com/watch?v=4UAPAuTvMtw