
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 01:18 PM
Hello,
I am trying to extend the script include 'SCPopularItems'. This script include is not read only, but there is only one method contained in it that I want to override. We'd like to leave 'SCPopularItems' OOB so we can continue to receive updates to it during upgrades.
I've looked at two official docs from ServiceNow on this as well as countless Community articles.
Right now the only difference (for testing purposes) between 'SCPopularItems' and 'MySCPopularItems' is I've placed a gs.log statement within MySCPopularItems to see when it's triggered. I do have additional customizations to it that I will place, but wanted to just prove out whether it will override the method contained within the OOB script include.
Can anybody tell me why this isn't working?
I've tried uncommenting and commenting the three lines of code for 'initialize: function()...'
New script include name: 'MySCPopularItems'
var MySCPopularItems = Class.create();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 10:25 PM
Sorry for the delay in responding, but I'm glad my previous response triggered the solution, as it was exactly what I was going for 🙂 I hate simple "do this" "answers".
When we create a Script Include that "overrides" another one, it doesn't automagically override it. We must use the new class in order for the overrides to apply. That is what I figured was the issue you were having as you did not mention using the new class name in your code.
We actually did this for a client with the OOTB Script Include used to create new User records because we wanted to use our own set of temporary bilingual passwords instead of the set used by SN. We created the new Script Include and pointed a couple of lines of code to use it so that the new passwords would be used but not change the rest of the functionality of the Script Include.
It's kind of hard to decide which method is "best": override/clone an OOTB record or modify it. I struggle with that all the time. Overriding or cloning something helps on upgrades because you do not have to review skipped records and you'll get any updated code automatically. BUT, at least the skipped record is a trigger for you to look at something that has potentially changed. Maybe you don't actually want the new code to be used because your code is important. Maybe you changed something and the newest SN code actually works the way you want it to now but you'd never know it unless you actively look at the code that you've cloned or overridden (which is not very likely). This gives you a means to revert back to the OOTB code. You can't compare code from 2 different records in SN directly, so you'd have to do it manually.
Another thing, like you mentioned, is some new code may have been introduced that uses the "old" OOTB code that you would prefer use the new Script Include you created. You'd have to actively search for those on upgrades to be sure your new code is used.
I know someone will jump in and say "best practice" says you never touch OOTB code. Well, I prefer the term "good practice", as the "best" way to do things is not the best way for everything/everyone/all the time. There is very rarely an absolute answer to everything.
Please remember to mark any response as being the correct one or helpful to you in solving the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 03:05 PM - edited 07-07-2023 03:06 PM
Hi,
As an OOB example of doing this, see:
https://[instance_name]/sys_script_include_list.do?sysparm_query=nameSTARTSWITHChangeProcess&sysparm_view=
there are others, for example 'Incident' and 'IncidentSNC'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 03:15 PM
Hi, yes, I've looked at and mimicked the OOB examples such as IncidentUtils and ChangeUtils; however not had any luck in getting it to work using them as an example. I've successfully used these extensible classes before (the OOB ones). This is the first time I've tried extending/overriding creating my own and I'm just not getting it to work. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 04:20 PM
Hi @sarah_kovar ,
Please post your script include, and how you using that new class. And add "gs.info()" in your script include to debug that. You can then review 'Script Log Statements' module to see the results.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 05:27 AM
Hi, I have my script include posted in my initial post. I already have gs.log statements.