Script Includes

From ServiceNow Wiki
Home > Script > Server Scripting > Script Includes
Jump to: navigation, search
Note
Note: This article applies to Fuji and earlier releases. For more current information, see Script Includes at http://docs.servicenow.com

The ServiceNow Wiki is no longer being updated. Visit http://docs.servicenow.com for the latest product documentation.


Scripting Glide and Jelly
Related Topics
Knowledge.gif Get the Glide Reference Book

1 Overview

Create script includes to store JavaScript functions and classes for use by server scripts. Each script include defines either an object class or a function. Script includes run only when called by a server script.

Consider using script includes instead of global business rules because script includes are only loaded on request.

2 Script Include Form

To access script includes, navigate to System Definitions > Script Includes. Script includes have a name, description and script. They also specify whether they are active or not, and whether they can be called from a Client Script.

Field Description
Name The name of the script include. If you are defining a class, this must match the name of the class, prototype, and type. If you are using a classless (on-demand) script include, the name must match the function name.
Client callable Makes the script include available to client scripts, list/report filters, reference qualifiers, or if specified as part of the URL.
Application The application where this script include resides. This field is available starting with the Fuji release.
Accessible from Sets what applications can access this script include:
  • All application scopes: Can be accessed from any application scope.
  • This application scope only: Can be accessed only from the current application scope.

See Scripting in Scoped Applications for information on scoped scripts. This field is available starting with the Fuji release.

Active Enables the script include when selected. Uncheck the active field to disable the script include.
Description Provides descriptive content regarding the script include.
Script Defines the server side script to run when called from other scripts. The script must define a single JavaScript class or a global function. The class or function name must match the Name field.
Package The package that contains this script include. This field is available starting with the Fuji release.
Created by The user who created this script include. This field is available starting with the Fuji release.
Updated by The user who most recently updated this script include. This field is available starting with the Fuji release.
Protection policy Sets the level of protection for this script include:
  • None: Allows anyone to read and edit this downloaded or installed script include.
  • Read-only: Allows anyone to read values from this downloaded or installed script include. No one can change script values on the instance on which they download or install it.
  • Protected: Provides intellectual property protection for application developers. Customers who download the script include cannot see the contents of the script field. The script is encrypted in memory to prevent unauthorized users from seeing it in plain text.

This field is available starting with the Fuji release.

Related lists on the form view:
Versions Shows all versions of the script include. Use this list to compare versions or to revert to a previous version. See Versions.
The Script Include form

3 How Do I Use Them?

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
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.


4 Privacy Settings

Most client-callable script includes are marked private by default (starting with the Dublin release). This privacy setting means that guests who access public pages cannot access client-callable script includes. Only the following script includes remain public by default because public pages need to access them:

  • GlideSystemAjax
  • SysMessageAjax
  • KnowledgeMessagingAjax
  • KnowledgeAjax
  • PasswordResetAjax

Client-callable script includes that you created or modified before upgrade to Dublin also remain public.

4.1 Changing Privacy on All Client-Callable Script Includes

To provide further control over all client-callable script includes, administrators can add the property glide.script.ccsi.ispublic. This property changes the visibility of client-callable script includes by making them all public or private. Configure the property as follows:

  • Name: glide.script.ccsi.ispublic
  • Type: true|false
  • Value: false
The glide.script.ccsi.ispublic property.

4.2 Changing Privacy on a Single Client Callable Script Include

To change the privacy for a single client-callable script include, add the following method to the script include:

  isPublic: function() {
   return [true / false];
  },

Use either true or false for the script include.

5 Enhancements

5.1 Fuji

5.2 Dublin

  • All client-callable script includes are private by default unless public pages need to access them. If an administrator creates a new client-callable script include in Dublin, it is private by default.
Was this article helpful?
Yes, I found what I needed
No, I need more assistance