ServiceNow Library Functions - What is the Right Way? What is the Penalty?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 11:14 AM
How do folks handle CLIENT-SIDE library functions???
And make them easily available wherever they are needed???
I am a firm believer in the Computer Science concept of "Reusability". I like to write things one time and then use them over and over again. This provides value to me and to my clients.
I have two types of Server-Side library functions, Utilities and Ajax Utilities. The Ajax Utilities are just a pass-through to the main Utilities library functions which do the heavy lifting. These libraries look as follows:
But I am struggling a little bit with how to handle things on the Client-Side. I created a client-side utilities library which looks as follows:
Form view:
Although the UI Type is set to "Desktop" (which I take to mean the Platform UI and NOT the Service Portal), my functions declared inside this record ARE available on the Service Portal (in Catalog Items). I had to use a Widget and Widget Dependencies in order to achieve this. That's what you are supposed to do, right???
This code is ALSO available on Platform UI pages such as the Requested Item page and the Catalog Task page. The very same OnChange() catalog client scripts reference my code on the Portal AND on the Platform UI Pages.
I have seen people saying that checking the Global checkbox will slow things down and that my code will be loaded to the client on every single ServiceNow page. That is concerning. But I find the other option, ScriptLoader() to be very clunky. It necessitates moving all my code that wants to make use of a library function into a Callback function. I don't want to do that! I tired it. It was a maintenance headache.
How can I determine HOW MUCH of a penalty my users are paying in order for us to be able to have convenient client-side library code? Is it really that bad? Wouldn't the library code be cached anyway? I need some actual numbers.
Or do others do things differently?
Here is my research on the use of UI Scripts and the Type and Global checkboxes:
Thank you for any help you can provide on this extremely important topic!