Scripts can automate processes, add functionality, integrate ServiceNow with an outside application and more.
TYPES OF SCRIPTING
1.Client Side : Scripts which run on browser or client side.
2. Server Side : Scripts which run on server side.
There are various types of API in ServiceNow which are discussed below.
- Business Rules : Runs on server side. It runs when a database action occurs (query, insert, update or delete).Before or after the database action is performed (runs as part of the database operation). Asynchronously (at some point after the database operation). On display (when displaying the data in a form)
- Client Script : Runs on client side.It is u sed for making changes to the appearance of forms, displaying different fields based on values that are entered or other custom display options. onLoad means the Client Script runs when the form or page is loaded. onChange means the Client Script runs when something specific gets changed AND also when the form or page loads. onSubmit means the Client Script runs when the form is submitted.
- Script Include : Runs on server side. Contains scripts which can be functions or classes. These scripts run only when called by other scripts (often Business Rules).Any server script which is complicated or reusable should be a Script Include (especially complicated Business Rules).
- UI Page : Can run in client & server side both. Used to create and display pages, forms, dialogs, lists and other UI components. Can be displayed on a standalone basis, or called as a usable component, as part of a larger page.
- UI Policy : Can run in client & server side both. Defines the behavior and visibility of fields on a form. Field can be made read only, mandatory or visible.
- UI Script : Runs on Client Side . Contains client scripts stored for re-use. Only used when called from other scripts.
- UI Macro : Contains modular, reusable components that can contain Jelly and are called by UI Pages. They also contain different types of scripts and may be called multiple times on the same page.
- UI Action : Can run in client & server side both. Creates the ability to choose a specific action such as clicking a button or a link. UI Actions put these items on forms and lists: buttons, links, context menu items & list choices.
- Transform Map : Runs in server side. It is used for importing data. It defines mapping relationships between tables. It can use Business Rules, other scripts and/or other options to import that data.
- Access Control : Runs on server side. Determines whether access will be granted for a specified operation to a specific entity. type of entity being secured
- operation being secured
- unique identifier describing the object
- Ajax Script : Runs on both client & server side. Enables the client to get data from the server to dynamically incorporate into a page without reloading the whole page.Ajax Client Scripts request that information be returned, or that action be taken, or sometimes both.Ajax Server Scripts fulfill Ajax Client Script requests
- Catalog UI policy : Can run on both client & server side .Defines the display of a variable set or a catalog item (from the service catalog).
KEEP IN MIND
- Use UI Policies rather than Client Scripts whenever possible. Because UI Policies are always attached to one table. And UI Policies often have a condition which must be true in order for them to run
CLIENT SCRIPT BEST PRACTICE
- Restrict List Editing
- Minimize Server Lookup
- Use UI policy instead of Client Scripts
- Use client scriots to validate data
- Avoid global client scripts
- Avoid DOM Manipulation
- Enclose code in functions
- Run only necessary scripts
- Add the isLoading check in Onchange client scripts
- Add the newValue check
- Bury the glideajax call