If you want to expand the capabilities of your script includes, look no further than extending your script includes.
If you are keeping your ServiceNow instance up-to-date, you may have noticed some new ways to code script includes. I’ll use the EventUtilBase (included in the Business Continuity Management application when installing the Crisis Management plugin) as an example.
Why would you want to extend off of an existing script include?
Well, the main perk is to be able to have all the functionality of the original, while being able to add new functions without modifying the original.
Below are 2 pictures: One is the original script and the other is the extension.
We will refer to the original script as the Base script.
In the base script, you will have all of your functions. I have cut it down to just the example we will be using.
This ‘exampleFunction’ in the EventUtilBase will always exist. But say we don’t like what it does, or we have a different situation that needs to happen. We can use the other script to override it.
Normally, our ‘exampleFunction’ will return ‘this is the base’. In the EventUtil, we can add our own ‘exampleFunction’ there. This will override the function of the same name in the EventUtilBase.
I have made it so it will return ‘this is the extension’
As for using this, instead of calling EventUtilBase for your scripts, you will call EventUtil.
EventUtil has access to all of the functions of EventUtilBase, but with the ability to override them!
This is a great solution for when you have a logic that can work across multiple items, but may need a special tweak for others. By extending a script include you can use the same logic without copy and pasting it into another script include while also being able to expand upon it.
All it takes to extend a script include is to use the first 2 lines of the script on the EventUtil. Replace the EventUtil with the name of your Script Include and replace EventUtilBase with the script include you want to extend.
That’s all there is to it!
Bonus tips: This can also work with Constants if done correctly. Ill talk about those in the next post!