logo

NJP

#3 What is After Business Rule in ServiceNow | End to end Tutorial of Business Rules in ServiceNow

Import · Sep 15, 2020 · video

[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 after business rule you will learn about what is after business rule and how it works what is after business rule after business rule is triggered when user submits the form and any action is taken on the record in the database that means if you want to take some action after user submits the form and data is saved in the database then after business rule is used major use cases of after business rule showing message after creation of a record create problem task after creation of problem racket delete associated records after deletion of parent rackets and update of work notes of child incident when parent work notes are updated so these are major use cases of after business rules after business rule without scripting so let's create few business rules without scripting and that is also after business rule in my personal developer instance so let's start with the first scenario where we will use insert operation that means after business rule that is after insert and the scenario we have is users should see message at the top when story is created so if i go to my personal developer instance and i go to stories so here we have stories and i go to business rule i will go to business rules so i will create a new business rule i will give it a name as demo for after without script and what i can do i will just select after insert and i can put over here actions and i will just add a message because we are doing this without scripting with just configuration so i will just mention here you have created new story and i will click on save so business rule is created now i will try to create a new story i will click on new and i will just do test after br and i will just click on save here you can see i can i am getting this message you have created new story so this is how you can create after insert business rule the next scenario we have is for after update and the scenario is when the priority of incident is changed to p1 then it should update in description so it will just update a string in the description that priority is p1 now something like that so how exactly i can achieve this i will achieve it with the help of after update however there is one more important thing now we are trying to create business tools without scripting however you still need to write a small script just one or two line of code just to process this business rule and the reason behind it we are using after update now if you want to populate any data in any business rule it's better to always use before business rule so that you can push that value before it gets inserted into the system but now you're using after update that's something you want in that case you can use current.update but ideally current.update is not recommendable approach so what you can do you can use set workflow as false so that it cannot run any other business rule so if ideally if i talk about the best practice you should not use current.update in business tool but even if you're using it you should use set workflow false as well so if i go over here and i go to list of incident i open list of incidents and i will open list of business rules as well so i will go to configure business rules i will create a new business rule i will give it a name so maybe demo for after i will check this advanced check box i will make it after i will make it update and then i will also put the condition so condition is if priority changes to p1 so i can just select changes to and i can select critical i will go in actions now here i can just put description now till now we are just configuring we're not adding any kind of script so this has become p1 and i will go to advanced now do you think if i just do like this and i save this business tool will it update it answer is no the reason behind it you have to trigger something to update it so what i will do i will do current current dot set workflow and you will make it false and then i can do current dot update that's it and if i save this this time this will also update the racket that means for the new value which we are trying to put as part of the p1 but at the same time it will not run any other business rule of the system that means you're not going to trigger unnecessary of business rules while doing this so in that case i will do a quick test i will open an existing racket not though because we have to change the priority so if i open the list of incidents and open that incident where priority is not p1 because we have to upgrade to p1 so let's say this one if i go over here i don't have any description you can see i will just change the priority that that i can do with the help of impact and urgency and i will just put the work notes now if i click on save you can see it says this has become p1 that means your business rule ran successfully after update business rule that's how you can create after update business rule after business rule with a scripting so let's create few business rules for after business rule that is also with a scripting in my personal developer instance so starting with first scenario that is for insert that means after insert and it says user should see message at the top when story is created it's kind of same which we used earlier but there's another requirement that is it has to populate with number now when you will use configuration you cannot make things dynamic because it has to populate number every time it creates a new racket for the current record which is just created which you cannot achieve it with the help of configuration so that's the reason i just wanted to show you the difference that how exactly it is different from with configuration and without configuration but and that is also with a scripting so if i go to my personal developer instance and i go to stories and i go to stories over here and i will go to business rules same business rule which we created and that was done with configuration here is the one demo after without script the only change i will do this time i will just add a script i will keep the business tool as it is so but i will just change something for example i will remove this message from here but this time i will do it from script i will keep this as it is because we want after insert and if i come over advanced and i come over here so i will do gs dot add info message and then i will do here you have created the story and we will give it a number and that will be plus how can i show that i just i can just do current dot number with the help of current dot number i can access the field value the field value which i can mention after current so i have got number field so it will automatically capture the value of that particular incident and that is number so in that case i will do semicolon and i will click on save now i will activate this script because this is inactive so i will save it again and now i will create a new story so i will go to stories click on new i will just give random maybe i will just do test for br and if i click on save absolutely you can see that we are getting this message you have created the story same and this is also dynamic now because you can make this dynamic only with the script you cannot do this with the help of configuration so that's a difference between configuration and scripting without configuration so this is how you can create after insert business rule and that is also with a scripting the next scenario we have for after update and where the scenario is when the state changes to work in progress then scrum tasks should be created so whenever i'm changing state to work in progress system should automatically create scrum tasks maybe let's say just one scrum task so if i go over here and i will just go to business rule we can use the same one this one and i can change the values so here i will do after update and here i can put state is work in progress so maybe i can do changes to work in progress that means whenever state will change to work in progress system should automatically create a scrum task so in that case i will go over here i will remove this one and what i will do i will do where gr equal to new glide racket and i can put the name of that table of scrum tasks which will be rm underscore scrum underscore task that's our table name we will do gr dot initialize we will do gr dot story we have to do the same story so i will do gr dot story equal to current dot society semicolon and i can do gr dot maybe short description and then i can do this is a test for br and that's it and i can do gr dot insert you are done and if i click on save so business rule is saved now i will update the state for any any one business any one story so if i come over here so you can see it's in draft mode and if i come over here you can see i have four tasks that's okay i i just have to create a new task so if i am changing it to work in progress and maybe i will just put some acceptance criteria if i click on save and yep you can see that we have fifth scum task and that is this is a test for br that means it is automatically creating that's one scrum task after updating updating the state that's as for the condition you mentioned in your business rule so this is how you can create after update business rule and that is also with a scripting

View original source

https://www.youtube.com/watch?v=88vO-kEmHz0