logo

NJP

System Events | ServiceNow Tips & Tricks

Import · Jan 05, 2023 · video

foreign fast we are going to talk about system events in this video so if you're new to servicenow and trying to understand or work with events you are going to love this so let's first understand what is an event something noticeable that has occurred in the system which might also become a triggering point for any action to happen is called an event working with events might sound complex but if you understand these three steps it's gonna be super duper easy so in order to work with events you need to register the event generate the event and respond to the event oops confused let's understand this by a simple example so we all have our phones whenever your phone rings you pick up the phone that's because you have a kind of registry in your mind that whenever the phone rings you need to respond to it when your phone rings it's a kind of event that got generated and when you're picking up the phone you are actually responding to that event so events work with similar concept when a service desk engineer changes the priority of an incident caller should get notified with a new priority also a log statement is generated with a message incident number is updated with new priority let's get started and follow the steps first we need to register the event in order to register the event we need to go to event registry under system policy and create a new record over there wherein can provide event name table also it's best practice to give details in fired by and description Fields so that if someone else is working on this he knows what's going on and that's it you can submit the record and event registry is done so now the event is registered servicenow knows that this can occur like you know your phone can ring but it will not ring unless someone gives you a call right so what's next now need to generate the event before we generate the event make a note that events can be generated only via server-side Scripts you can use business rule workflow scripts script include or any server-side script but events cannot be generated from client-side Scripts the case we are going to use business rule to generate the event so this is our business rule which runs on incident table when priority changes and here we are generating the event in the advanced script section an event is generated using event queue method in Glide system class which takes four parameters the first parameter is event name which we used for the event registry second parameter is Glide record object you can pass any Glide record object you're using in your script here we are passing current third and fourth parameters are optional and you can pass any values as per your requirement in this case we are passing the display name of logged in user and a priority of incident because we need it for our use case to be completed so you knew your phone can ring and now it's ringing what next you need to respond to the call or you need to respond to the event service now when it comes to responding to the events you can do it in two ways either you can configure an email notification or you can run a script of your choice will do both in this case as per our use case we'll send the notification to the caller that the priority has changed and will run a script to log a message with script can I run any business rule client script or any script of my choice a good question so the answer is no there is a special kind of server-side script you need to configure to respond to the system event and it is called Script action will come to this in a moment so let's first configure the email notification and here is my email notification I want my notification to be sent when this event is triggered and I have selected my event here I want to send it to the caller so I have selected that you can use even parameters as well to define the recipients and this is my subject line and the email body which takes locked in username and incident priority from event parameters so the email notification is ready now let's con configure the script action to log a message you can find script actions under system policy events click on the new record provide the name to your script action and select the event here I've provided the log message which is taking the incident number from the current object and incident priority from the second parameter of the event I prefer to provide source to the log message so that it is easy to find in the logs so we have followed all three steps we have registered our event in the event registry we have generated our event using the business rule and we have responded to the event using email notification and the script action so now it's time for verification so let's get into my personal developer instance and change the priority of this incident from 4 to 3. [Music] hit update so the priority is changed to 3 Let's see if the event was triggered or if the notification was sent and the lock was generated or not we configured a notification to be sent to the caller of the incident in this case it's David Miller so let's first check the notification under system logs and here you go the notification has been sent to David Miller with the subject line priority for incident has changed let's see the content of this notification you can notice that it's triggered by the event which we generated incident.priity.update and you can preview the email to see the content of it hi David Miller your incident priority has been has been changed to three by system administrator so it worked let's now check if the log message is generated or not so let's go to system logs all we had our source write that and here we go so we have our log message as well incident is updated with new priority equal to 3. yippee so all worked fine that's pretty much it for the events however I have one bonus information for you so the bonus information is that you can schedule the generation of event for a particular time for example if you want after 30 minutes of you putting incident to cancel state it should get closed it can be done by scheduled event which can be generated using the syntax GS dot eventq scheduled and this method takes five instead of four parameters the fifth one is the time you want to trigger this event on so try it out and have fun with system events [Music] thank you [Music]

View original source

https://www.youtube.com/watch?v=QQr-BkX0po8