Use script includes

Script includes are found under System Definition or System UI. You can call existing script includes from a script.

To create an entirely new script include, you can follow the format of any of the existing script includes. In the example, the name of your Script Include is 'NewInclude' and there is a single function called 'myFunction.' It is important that the name of the script include match the name of the class, prototype, and type. When you create a new script include and give it a name, the system provides you a code snippet with the class and prototype set up properly.

var NewInclude =Class.create();
 
NewInclude.prototype={
   initialize :function(){},
 
   myFunction :function(){//Put function code here},
 
   type :'NewInclude'};

You could then use the 'myFunction' line like this:

var foo =new NewInclude();
foo.myFunction();
Note: Try not to modify a ServiceNow supplied script include. If you want a script include that does something similar to an existing one, copy it and make changes to the copy or consider extending the object. This is a common practice when using GlideAjax.