Proposed Method for Modifying OOTB Script Includes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 07:21 PM
Proposed Method for Modifying OOTB Script Includes
I have a method that I plan to use for modifying OOTB script includes. I'm looking for feedback on the method. What do you see as the upsides or downsides of this approach?
Sometimes we need to modify OOTB script includes
First, I'll acknowledge that the standard answer when it comes to modifying OOTB script includes is that OOTB script includes should not be modified. However, there are situations when we need to modify an OOTB script include. Here is a common example. There is a method in the OOTB script include that is called from multiple places in other OOTB scripts. You need to make a change to that method. In this case, if you can either modify all of the other OOTB scripts, or modify the method in OOTB script include. In this case, modifying the OOTB script include is the right thing to do.
Modifying OOTB Script Includes
This approach is a modified version of the pattern that ServiceNow uses when they have a base read-only script include usually with an "SNC" suffix, and a customizable script include without the "SNC" suffix. For an example, see the ActivityUtilsSNC and ActivityUtils script includes in your developer instance.
There are three steps.
Step 1:
Rename the OOTB Script Include and then create a new script include with the original script include name
- Open the OOTB Script Include you want to customize.
- Add the suffix "OOTB" to the script include name. save the record.
(This is the only change that you need to make to the OOTB script record. When you change the record name, the name change automatically cascades through the script.) - If necessary, open the OOTB script include again.
- Remove the OOTB suffix from the name, and do an insert and stay to create a new script include record.
Now you have the original script include record with a different name. And a new script include record with the original OOTB script include name.
At this point, any new or existing calls to the script include will go to the new script include.
Note: The reason we do an insert and stay to create the new script include is so that all existing settings in the OOTB script include are set in the new script include.
Example (modifying the AbstractAjaxProcessor script include)
- Open the AbstractAjaxProcessor script include.
- Change the name to AbstractAjaxProcessorOOTB, and save the record.
- Reopen the AbstractAjaxProcessorOOTB if it is not already open.
- Change the name to AbstractAjaxProcessor, then Insert and Stay to create a copy of the record.
- Remove the "OOTB" suffix (so that it has the original name), then insert and stay.
Now any calls to the AbstractAjaxProcessor will go to the new script include. All GlideAjax calls will go to the new script include.
Step 2
Make the new script include record extend the OOTB script include.
- Open the new script include record (the one that has the name of the original script include).
- Remove everything but the type from the prototype.
Example using the AbstractAjaxProcessor
AbstractAjaxProcessor.prototype = {
type: "AbstractAjaxProcessor"
}
- Update the prototype so that it extends the renamed OOTB script include
Example using the AbstractAjaxProcessor
AbstractAjaxProcessor.prototype = Object.extendsObject(global.AbstractAjaxProcessorOOTB,{
type: 'AbstractAjaxProcessor',
}
);
- Save the record.
Now all existing calls to the script include will go to the script include you created, and will use the methods in the original script include.
Step 3:
Add your custom code to the new script include record.
- Override methods that you need to override.
- Add new functions
- ...
Upgrades will be Easier with this Approach
In the past, when I've made changes to OOTB script includes, I've made my changes in the script include record. Then when ServiceNow released a new version of the script include, I would have to compare the new version with my customized version and try to reconcile the two. This method was time consuming and error-prone.
With this method, I will only need to do the following when ServiceNow makes a change to an OOTB Script Include that I've customized.
- Revert to the upgrade version of the script include.
- Rename the script include so that the name has the OOTB suffix.
Now I will have retained my customizations and be using the latest functionality provided by ServiceNow. - Next, compare the new version of the OOTB script include with the previous version to see if ServiceNow made any changes that will impact my customizations.
- Finally, update my customizations in the separate script include if necessary.
That's it. Please let me know if you have any questions and what you think of this approach.
Thanks, Cody

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:36 PM
Hi,
Thanks for your comment.
I understand that the best way to customize it OOTB script include is to not customize it. However, as you note in step 5, if you have a script include with a different name from the original script include, then you have to update all references. If the references are themselves in OOTB scripts then you end up having to modify other OOTB scripts sometimes many OOTB scripts to avoid modify the OOTB script include. So with the constraint that you have to modify the OOTB script include, what are your thoughts on this approach?
Let me know if you have any questions. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:49 PM
Your replying on a AI generated message 🙂
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:48 PM - edited 01-16-2024 12:48 PM
Hi there,
Just wondering what your source is for "I'll acknowledge that the standard answer when it comes to modifying OOTB script includes is that OOTB script includes should not be modified".
ServiceNow changed its approach for modifying OOTB artifacts a few years ago already.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 07:05 PM - edited 01-16-2024 07:24 PM
Hi Mark, my source for saying that "the standard response to modifying OOTB script includes is that you shouldn't modify them" is my own experience. That is the response I get whenever I bring up the topic of modifying OOTB script includes. 😀
I appreciate you letting me know that ServiceNow has changed their approach to customizations. I found this KB article that discusses the approach: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0553407
I think that the approach I discussed conforms to their approach in that I am changing the OOTB script include. My modification is that I'm changing the script include name. I am putting the customizations in a new custom script include instead of in the OOTB script include, which doesn't conform with the approach they've described. Of course, they are not talking specifically about modifying script includes. They are talking about modify OOTB artifacts in general.
Let me know if you have any questions.
Thanks, Cody