#4 What is Async Business Rule in ServiceNow | End to end Tutorial of Business Rules in ServiceNow
[Music] in order to subscribe to my channel please click here or click here please share comment and like my videos and channel hello guys welcome to sas word service now in this video we will talk about async business rule you will learn about what is async business rule and how it works what is async business rule async business rule is triggered when user submits the form and any action is taken on the record in the database however it creates a schedule and run the job async business rules are kind of similar to after business rules however it runs in the background and used when system can wait to process and return the value if i give you the difference like an after business rule or maybe in other business rules we wanted some kind of population of the rackets right away so if you're updating the assignment group if you are updating the description you want those values to be populated that means you want those actions to be taken right away users should see those data right away when business rule is running but in an async business rule system can run and process the action in the back end and once system will get the response then only it can process further actions and that's how async business rules are used if i talk about the major use cases so major use cases of async business rules are like create event so user is taking some action maybe changing some field and you want to create an event and then with that event you want to send a notification now that notification system can definitely wait because user does not want that value on the form right away so user can change the value on the form but system can process it with the help of async business rule and then create the event and then create the notification in the background now another use case is send rest api call to another application on update of incident so let's say you want to create a racket in another system in that case when you update the current incident maybe you change the state maybe you change some some fields in that case why do why would you create before or after or any other business rule you don't have to you have to use async business rule the reason behind it because you don't have to get the data right away you can just write async business rule and then system will process the requests and the call to the under the system create the record in another system and maybe it will update the racket maybe later as well in your system after getting the response but you don't need those things right away and that's the reason you use async business rules and another major use cases i would say calculating slas now slas is something if i talk about end user does not need right away user can wait for it even slas are being used for it people not for not by the end users so even if user is creating and creating an incident if you want to calculate the slas you don't have to do it right away it shouldn't be quick so for that rather than using after you can use async business rule to update the slas previous version the async business rules do not have access to previous version of a racket that means you cannot use methods like changes changes to and changes from in your script however these like values these methods can be used as a condition of business rule so if you have those conditions like field and changes to that definitely you can use but you cannot use it in your script while writing async business rule and when you have to write the script you cannot use these methods async business rule with a scripting so let's create few business rules with scripting for async business rule the first scenario we have for insert that means type is in async and operation is insert and the scenario we have is when incident is inserted with priority one then system should create an event to send a notification so if i go to my personal developer instance and i go to list of incidents now why i am creating this as async business tool because i don't have to populate something or push something directly on the incident right away i don't need that so that that's the reason i'm going to create async business rule so if i go to list of incidents and i will go to list of business rules then and i will create a new business tool so before that i will just make it inactive and i will click on new i will give it a name so maybe demo for demo for a sync and i can just check this check box i will make it async i'll make it insert however i have to put the priority because that's the requirement we have we will pay priority is critical and i will directly go to advanced now here i have to generate the event so i can just do gs dot event queue here i have to put the name of the basically uh the key event which i have to create in the even registry so i will just maybe put incident dot p1 dot inserted i'm done and i will do comma now this can be current then i will do comma then here i will basically put the parameter now i have to send the notification so maybe i can put the assignment group that is something i can put over here so i can just do assignment current dot assignment group and maybe i can just put here current dot assign to that's it and i can just save this now i will go to event registry i think this way you are also able to learn events as well that how we generate events and service now so with one training you will get two different learnings so i will go to registry and i will basically copy this i will go to registry click on new i will put the name over here and i will select incident as well it says fired by i will just mention br and i will save this so it is saved now i will go to notifications so i will go to notifications i will click on new i will give it a name send p1 i will select the table now here i will select event send when event is fired and our event is incident i'll see there should be incident.p1c i have this incident.p1.inserted if i select this here i will do who will receive so for that let's let's first click on save now i'm not seeing parameters to be selected but now you will see that because it has become advanced view so maybe you can mention even param1 contains we can also put it for parameters or maybe you can just put right here maybe or maybe we will send it to application development and i will just click on save so it will be sent to application development and that's it and i will save this now i will go to incident racket now here i will create a new incident let's see what happens i'm going to create a p1 incident i will select the color i will select group as well let's not do that even if i will select it i think it won't matter because we have selected a different group for sending a notification so i will just do like this and if i click on save this will definitely trigger that event how can i know that if it has triggered the event or not i can just go to events here and if i just sort this out yep you can see here our our event was generated with the same process because we wrote the business rule so our business rule basically generated the event so this is how you can generate the event and if i go to my incident you will see that i think it should should have sent notification maybe i will just go to email logs in that case i can see it better i think this sent something yep you can see because we didn't put anything in the body we didn't put anything else anything in the subject that's the reason i'm not able to see anything as a subject and all other information but you can see email was sent so this is how if you have to generate events with the help of business rules then you can use async business rule rather than after or before so this is the best way to utilize async business rule for this kind of requirement where user does not want the data the value to be returned right away so in that case async business rules are the best the next scenario of async business rule is related to update that means async update and the scenario is when assignment group changes then update the task sla group to current assignment group so if i go to my personal developer instance and i go to list of incidents and i also open any random incident let's say this one i will go to task sla over here now we have to update the assignment group do we have assignment group no we don't have any kind of field in this particular table so if i open this in a new tab and if i see this is task underscore sla it doesn't have any kind of group so maybe i will make it as a task group just a new field i will add over here so if i open task slas i will add a new field form layout and i will add maybe group and i will just do i think i have to make it a string now i have to make it reference not string so i will make it as a string i will select cis user group so i will do this one and i will add it it's added and i will make it at the top and i can just click on save so this field is added i will click on close so what i have to do i have to update the current assignment group in the task sla and if i close this and basically when you exactly you have to do that whenever you are changing the assignment group so i will go to business rule now i will write a business rule so maybe we can just open the same one that's for demo for async now i will go to when to run here i will make it update it has to be for update now it's up to you if you want to run it for both you can also do that now here i will just change the condition because this time condition is for assignment group if assignment group changes see if i will do assignment group changes i will go to advanced i will remove this one and now i will do where gr equal to new glide record and here i will do task underscore sla that's a table we have i will do gr dot now we have that field task so i will do task comma i can do current dot society and then i can do gr dot query and then i can do gr dot i think for that we can just do while here i can to while gr dot next if i have the record now here i can do gr dot underscore group equal to current dot current dot assignment group that's it that's what you have to do so i have task and i can just update it and it's async now do i have to do current dot update now that's an important part over here if you will do that you don't have to do current because this is for gr update this particular record has to be updated so will you do current no we will do gi dot update so i will do gr dot update that's it and i can just click on save and now i will go to any existing incident let's say this one and if i will come over here do i have task sla i don't have in this one so i will just look for the incident where i have task sla so let's say this one so i have two task sla over here you can see that so what i will do i will just pull that particular field which we added will just add it over here now what i will do i will change i will change the assignment group so maybe i will do it database if i will do that let's see what happens if i click on save if i refresh this you can see that it has updated data brace group in this particular field so that means i think if you i think you now you understood that why we used async i could have used after as well but i don't have to why i have to uh put an impact to the system because async is the best way because i don't need this value to be populated right away because there's just an sla which can which people can see later as well it has to capture the value it will be captured the sli will definitely run as it is but i can update it whenever i want because there's no dependency on the user the user does not have to see this so that's how i have to use async business rule because i don't need this value right away i can wait for it so that's how you can create different types of async business rules as per your requirements and as i told you earlier there's another major scenario is integration so whenever you are doing any kind of integration i would recommend to always use async business rule to trigger the call from servicenow or if you want to create something in another system that those kind of integrations you should always do with async business rule
https://www.youtube.com/watch?v=z_eBoAuTbeQ