logo

NJP

ServiceNow – Application Development Fundamentals – Notifications Solution

Import · Aug 22, 2022 · video

hi everyone this video is intended for all students of the servicenow application development fundamentals course in that course we build an application from start to finish and part of the application involves developing a notification that will be sent out to all requesters of a loaner device to inform them that their device is ready to be picked up you would have noticed that there are also a couple of challenge exercises as well to create two extra notifications one to inform the requested that the device is nearly ready to be returned and second to inform requesters when their device is overdue in other words when they haven't returned the device by the due date so in this video we're going to have a look at how to create those two extra notifications before we go ahead and create the two new notifications let's quickly recap how we created the first one so we created in total five different objects that work together to finally trigger the notification so we started off with a system property that will determine when the notification will be sent how far in advance of a learner device being picked up the second was an event and that event was used was triggered to determine when exactly the notification will be sent thirdly we created a scheduled job that actually runs and triggers the event by referencing a script include that contains the functionality for triggering the event as well as to determine what records we should send the notifications for and then finally we actually created the notification itself that was triggered from the event so just keep all of these objects in mind as we go ahead now and look at creating the two new notifications okay so the first thing that we have here is a system property now pay attention to the name whether it's uppercase or lowercase or a mixture of both that's important next we have an event again pay attention to the case of the event name okay because you'll need to reference it in a script and case is important okay so we have our pickup event the next thing we have is a scheduled script now in our lab we modified this if you recall to include two functions from a script include so we're actually calling two functions here the first one here get null pickup reminders is used to what it's used to obtain a list of records that are ready to be picked up a list of devices that are ready to be picked up we're going to send reminders to those requesters okay and that is what the second function will do will be actually to trigger the notification all right and next if you have a look at those respective functions in the script include and we just scroll down here a little bit to this first one here to get now pick up reminders this one here obtains an array of all requests that need to be picked up okay and then we also call the second function as well send pickup reminder okay so this is actually doing the work of uh triggering the notification in the form of an event here okay you'll notice here the event here is being triggered all right okay and then finally the notification that you have created will be triggered based on when the pickup event is triggered okay if you look at the contents of your notification again you should have a line in here referencing a email script okay that's the email script that you basically copied and pasted from the business rule and put into a mail script and made some minor modifications to it so that it would work and print out the password in your email let's have a look at that email script so if we come here this is basically a copy and paste from our business rule that we tested earlier that contains a basically a direct call to the the web service here so actually calling uh using this url here and we're getting or making a query based on the asset tag of the current record the configuration item that was specified there okay so let's go ahead and test this first make sure it's working still so if we come to a device here a request rather i'm just going to remove that pickup reminder because i tested this earlier just to make sure it was working so that field needs to be blank that's part of the conditions in the script so that will need to be blank in order for the event to be triggered importantly with your testing state needs to be ready for pickup okay the item type needs to be laptop and you need to have a configuration item here for which you have a password in your other instance okay and i have already okay so if i come back now to my schedule script and then execute that and now come back to my request we have the timestamp here if we go to our logs and refresh this we can see a confirmation that we actually got a 200 response back which is good and we've got the password in there and i've also printed out the entire object here that was returned which means also that theoretically hopefully we should also have an email so if i come to my list of emails refresh this list again this is the email a device is ready to be picked up let's open it and take a look and preview the email and we can see here the password has been generated here so that's what you should have right now now there was a challenge in the book to create two extra notifications one for reminding the user to return the device within 24 hours so within 24 hours of the the end date we should send a reminder email to the user saying please return the device it's due tomorrow or soon and then the second notification would be to send an email when the device has not been returned it's overdue we need to inform the user to bring it back as soon as possible so let's go back to servicenow studio now and go to our script include and if you had taken a closer look at this before you would have noticed that there were actually functions in there to do precisely those actions to actually generate the respective events that you need to trigger a notification to remind the user to bring the device back as well as when the device is overdue so essentially you're just replicating what you have already performed but to create two extra notifications and two extra events to trigger those notifications so let's go ahead and look at our script include and find exactly what events we need to create so if you go up to the top of the script include we can see we're using this uh variable here this reference to a pickup event right here so the ones that we need for our two other notifications uh these ones here uh the return one as well as the overdue one you don't actually need uh this reminder event uh for our exercises here we just need return and overdue okay so let's go and take a quick look at the events that i've already created so in my event registry i've got one here called overdue and another one here called return okay with the respective descriptions here all right again pay attention to the case of the event name that's important because often if it's a different case that's where you'll trip up the event won't be generated if the event is not generated then your notification will not be triggered okay so we need a new scheduled script for the return first of all let's take a look at that let's open up our existing scheduled job here because we can just make a few modifications to this and all work just fine so i'm going to make a copy of this and do an insert so i will just change the name here to learn item return and then come down to our script here now we need to call two different functions here and replace the two that we've currently got for picking up the device so to do that just let's just take a look at the script include once more so we'll go through our script include now those two functions are actually all the way down the bottom here if we go to the first one here it's called get null return reminders now there is a very small error in the script actually so if you try to just call those functions as they currently exist they won't work or the first one will not work so if you take a closer look here i've actually commented out the error and added in a correction so in your script include you will have this line here to get the temp date variable by calculating the notice time which is the current time and adding the return remind time and that won't work because you can see here we're actually adding some kind of empty string at the end here and that will trip you up so what i have done here is basically just use exactly the same variable and calculation that was in our original function for the reminders so i've actually created another variable here called notice time and then we've just added the return remind time which is a reference to the system property that we created earlier so that by default that was 24 hours and then i've added one more correction to correspond to that so that the query here references that new notice time variable because in the original it was a reference to the temp date i think and that didn't work okay so just take a look at this script take a screenshot of it and modify your script include accordingly so that's the first function that we need get now return reminders so i can take that i'll just copy that and the second one that we need is the last one here send return reminder okay again which basically just generates the event and which triggers the corresponding notification that we still need to create okay so let's go back to our scheduled script this one here first of all i'm just going to do an insert and stay here just to be on the safe side that i don't accidentally copy over the original record and i'm just going to modify the names of these two functions here so the first one here was get null return reminders and the other one was send return reminder so we'll just change that okay and that's all we have to do okay so i will save that and the other thing now is to create the notification now i've actually created this notification in advance so if i come down here and open up the learner return notification okay we can see here in the conditions for the trigger it's going to be triggered when that event is generated that return event right here okay and as as for the content well you can just adjust this accordingly you don't need to make a web service call you don't need to obtain the password for this device you just need to inform the user to bring the device back so let's go ahead and test this now i will go to my original request here two things to keep in mind again pay attention to the conditions in the script include let's just quickly review them once more so if we come here to the first function that we're going to call we're looking up all records here with the state of 17 which is checked out and where the return reminder date has not been set yet okay and also importantly where the end date is within the next 24 hours okay so i'll come to my request here let me just check the date here uh that's the 24th so that's in a couple of days so we need to make that a little bit earlier so i'll make that tomorrow and uh that time is within the next 24 hours just make sure your time zone is set as well makes a lot easier to test okay so if your time zone is set to your actual time zone and not to gmt time then you'll make testing a lot easier so all right so we'll accept that and then the return reminder has not been set so that's good and we are ready to go so i'll save this one more thing before i forget we need to change the state from ready for pickup to checked out because that was also a condition in the script include so let's save that and now we can go back to studio and our scheduled job and then execute that and we should find that in our event log this time not in the general log which is the one i showed you earlier uh the event log if we just refresh that we've got our return event that's been triggered here which should also mean that we have our email notification also triggered and this is the one here return your laptop okay so that's working as expected now and now we can go ahead and create the final notification which is to remind users to return their overdue devices if they haven't been returned by the due date so again we'll go back to studio here we'll just take our existing scheduled script and then make a copy of this and create the one for overdue devices so before i do anything let's do an insert stay and we'll need to go into our script include again once more just to find the respective functions that we need to get the list of devices that are overdue and then to trigger the event with the other function to generate the notification so back to our script include so the overdue functions are actually in not in chronological order so they're at the top here so we've got our get over g request so that's the name of the function the first one that we need to call okay uh again if you have a closer look at the conditions here we're looking at all devices that have been checked out where the end date has already passed okay so that is the first one we need get over to your request so let's pop that in here and then our second function is let's come back it's not this one here time to remind overdue it's the one after that send overdue reminder so i'll just copy that and put that in my script include right there okay we can go ahead and save that so it's one scheduled script completed okay it's actually defaulted back to our return sometimes it happens in studio just refresh the whole page if you do an insert sometimes it refreshes and shows you the old record so if we come to our list of schedule scripts and open up the one for overdue that's the one so just be careful conscious again of what record you're working in it's very easy to be working in the wrong record and then errors will occur okay your testing will fail uh let's go back to the script include we just need to take a look at that one more time and let's go to the i think it's a second function here that we're using the send over g reminder again just take a look here at the event that's being triggered here okay it's this one here this overdue event what one is that okay let's go back up to the top this overdue event here is called overdue okay so in the book i don't think it actually makes mention of this at least in the book that i have so i i've already gone ahead and created the overdue event uh over here all right so that's the one that will be triggered that's the one that you need to use in your notification okay so if we come back here and i do believe i have a notification for this already set up and ready to go okay again no web service calls here just some standard text here just to remind the user politely to bring the overdue device back and then importantly the trigger here is that overdue event that is referenced again in the script include so let's go ahead and test this let's go back to our original request here uh the state is checked out now the end date will have to be before right now uh so let's take a look at the time so i'll just make that the 22nd 11 o'clock that should work just fine okay and i might just make the start date a little bit earlier as well otherwise our previous business rule that checked whether the start date is before the end date will fail so that is looking okay now uh we don't have or doesn't really matter actually the overdue reminder because that will be updated we will actually have the ability to send over og reminders every 24 hours okay so let's do that so you won't just get one overdue reminder you may actually get more uh okay so now that we've got that let's go ahead and execute that scheduled job that we created the overdue one execute okay let's come back to our events once more refresh we have our overdue event here now that's looking good and that should also mean again that we have our overdue reminder here notification okay so that's how you go ahead and create basically duplicate what you've already created with your scheduled job just make some more some modifications to that for your return reminder and your overdue reminder as well notifications um create the respective events create the respective notifications and you're good to go okay so thanks very much for watching

View original source

https://www.youtube.com/watch?v=giTe5Sxr1C4