logo

NJP

#6 Business Rules Best Practices | 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 you will learn about business rule best practices you might be creating different business rules as a developer or admin to achieve the functionalities however it's very important to know what standard practice you should follow or keep in mind while creating business rules and performing scripting in business rules so let's see that what are the best practices of business rules in service now so starting with first best practice which is know when to run business rule it is very important that you should have full understanding of selecting when a business rule should be triggered as you know we have different types of business rules which you can run on different operations like async you have display you have before you have after and you also have different operations like insert update query you have delete as well so once you have the requirement you should you should know that what values to be selected to achieve that kind of requirement so it's really really important to know when exactly you have to run the business rule as per the requirement you have your customer next is use conditions and business rules this is very important you must have seen when i was creating business rules in previous sections i was definitely putting some conditions like priority is p1 or we have any kind of other conditions or maybe assignment group is not empty that's something you should always put in business rules because like as you know business rules are evaluated whenever an insert update delete or query action is made to a racket so it is really important to ensure that you are using conditions and the conditions are evaluated before the rule is executed so if condition is met the script is evaluated and executed so if you want to save basically if you will not use the condition so for example you're not putting any kind of con condition in business rule then system will assume that the business rule should be evaluated and executed for every action to the record of the selected table in that business rule that means every time your business rule will be evaluated even that business school doesn't have to take any action maybe on that particular action which would just happened but your business school will still run will still do the evaluation that means you are kind of impacting the performance of the system you are unnecessarily utilizing the utilizing the resources of the system that's the reason it is very important to understand that you have to use conditions in business rules which will save lot of basically performance of your system next is code should be in functions now this is very important for developers who basically perform scripting in service now and create business rules and do the scripting and business rules basically when you create a business rule and select advanced check box then script field automatically shows function which in which you can write a script so it's very important that you follow the same structure you should not try to remove that function and if you will do that if you will do that then variables and other objects which you are using in your script they will be available to other system scripts as well so whatever server side skips you have maybe in other business rules or maybe in other scripts you have written system basically those scripts will have access to the variables and and objects you will create in your this script now this can lead to the unexpected behavior in the system and you won't be able to troubleshoot in a better way that what exactly the reason is so it's very important that as a developer whenever you are writing a script in business tools you always need to write that script in function you don't have to remove the function you cannot do that and this is definitely not recommended i think nobody will recommend that approach so all the script should be in functions next is do not use recursive business rules so you should not use current dot update in a business rule script as update method triggers business rules to run on the same table for insert and update operation which can basically which will lead to a business rule calling itself again and again so if you are writing for example you're writing before business rule you should not use current dot update i would say that's kind of a mandatory thing you don't have to write for after or maybe for async you can definitely try to use current.update but the important part is for after and maybe for after business rule if you still want to use current.update you should always use set workflow as false so that it does not trigger any other business rule but overall current dot update is not recommended in service now using in business rule and if system finds this current dot update then system will automatically log an error however this will still cause some performance issues system will still alert you that hey you are using some recursive method you are you don't you don't have to use current.update system will definitely alert you and put an error in the log but still it will give performance issues so you have to make sure that you are not using recursive business rule and you're not using this current dot update next is do not use global business rules so when you select global in the table field of business rule then it becomes global business rule so you can call global business rule from any script and global business rules run on every page which will not be efficient and impact the performance so if you will create the global business rule so it because system doesn't know which table is for that means it will run in every table whatever page you will open global business rule will run so rather than using global business rule you should always use script includes those are the best way to call the script so always use script include rather than global business rules so these are the major best practices while writing or creating business rules while doing scripting in business rules so that you don't you don't give any kind of performance issues to your system and all your business rules run smoothly so i hope you like the whole series of business rules please let me know your feedback in the comments please like share comment and do not forget to subscribe to my channel and have a great day

View original source

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