0% found this document useful (0 votes)
50 views

Scripts

This document describes different types of scripts used in ServiceNow. Business rules contain scripts that run when a database action occurs, like on insert or update. Client scripts are used to modify form appearances and behavior. UI policies define field visibility and behavior based on conditions. Script includes contain reusable scripts that are called by other scripts like business rules.

Uploaded by

Dx Cat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Scripts

This document describes different types of scripts used in ServiceNow. Business rules contain scripts that run when a database action occurs, like on insert or update. Client scripts are used to modify form appearances and behavior. UI policies define field visibility and behavior based on conditions. Script includes contain reusable scripts that are called by other scripts like business rules.

Uploaded by

Dx Cat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Access Determines whether access will be granted for a specified operation to a specific entity.

Control type of entity being secured


operation being secured
unique identifier describing the object
Can be defined by roles, conditional expressions or scripts.

Ajax Scripts 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

Business Customizes system behavior


Rules runs when a database action occurs (query, insert, update or delete)
the script may run
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)

Service Defines the display of a variable set or a catalog item (from the service catalog).
Catalog UI
policies

Client Scripts Used for making changes to the appearance of forms, displaying different fields based on values that are entered or other custom
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
Client Scripts can also be called by other scripts or modules, including UI policies.

Script actions Contains scripts which run when an event occurs, for example
approval is cancelled
change is approved
problem is assigned
Can have a condition which must be true for the script to run. Commonly used to call a Script Include.

Script Includes 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).

Transform Used for importing data.


Maps defines mapping relationships between tables
can use Business Rules, other scripts and/or other options to import that data
Do not always include scripts.

UI Actions 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

UI Context Defines which "right-click menu" will pop-up in which area, and the menu choices that will be available
Menus
Note: If you use a left-handed mouse configuration, right-click means "click the other button."
UI Macros Contains modular, reusable components that can contain Jelly and are called by UI pages. They also contain different types of sc
may be called multiple times on the same page.

Note: Jelly turns XML into HTML.

UI Pages Used to create and display pages, forms, dialogs, lists and other UI components. Can be displayed on a standalone basis, or call
usable component, as part of a larger page.

Can contain
Client Scripts,
processing scripts (which are server scripts),
HTML,
Jelly,
UI Macros,
and also can call other scripts.
Note: Jelly turns XML into HTML.

UI Policies Defines the behavior and visibility of fields on a form.


mandatory
visible
read only
Use UI Policies rather than client scripts whenever possible.
UI Policies are always attached to one table
UI Policies often have a condition which must be true in order for them to run

UI Properties Designates what the instance will look like.

UI Scripts Contains client scripts stored for re-use. Only used when called from other scripts.

Not recommended for use.

Validation Validates that values are in a specified format.


Scripts
For example, a validation script can verify that the only value allowed in a specific field is an integer.

Workflow Used to create or change a workflow. Scripts can be run at any point in a workflow, or different scripts can be run at different poin
editor
Scripts also can be found inside every workflow activity and can be modified (although do so with extreme caution).
BUSINESS RULE

CLIENT SCRIPT AND UI POLICY

UI Policy : if you want to make your form field "Mandatory" "Read Only" "Visible" based on some field condition or browser load then you
can simply use UI Policy here.

Let's take an example : i want to make work notes field mandatory based on the state field value. so this is a simple straight forward
requirement. so here i will go with UI Policy. 

i will Create an UI Policy and set the filter condition State | IS | Resolved then in the UI Policy action i will set true for Work notes field. 

If you have a similar requirement but the work notes field should be mandatory on form Submission then you have to use here onSubmit
Client script because in UI Policy you can either set it on field change or form load ( only in these two scenario you can run the UI Policy
).

But Client script can be run on either onLoad() , onChange() , onSubmit() or onCellEdit().
Client Side (Client Script):

function onChange(control, oldValue, newValue, isLoading) {

      if (isLoading || newValue == '') {

              return;

      }

     

      var ga = new GlideAjax('asu_GetLocationData');

      ga.addParam('sysparm_name', 'getCampus');

      ga.addParam('sysparm_buildingid', g_form.getValue("u_building"));

      ga.getXML(updateCampus);

     

function updateCampus(response) {

      var answer = response.responseXML.documentElement.getAttribute("answer");

      var clearvalue; // Stays Undefined

      if (answer) {

              var returneddata = answer.evalJSON(true);

              g_form.setValue("campus", returneddata.sys_id, returneddata.name);

      } else {

              g_form.setValue("campus", clearvalue);

      }

Server Side (Script Include):

var asu_GetLocationData = Class.create();

asu_GetLocationData.prototype = Object.extendsObject(AbstractAjaxProcessor, {

      getCampus: function () {

              var buildingid = this.getParameter('sysparm_buildingid');

              var loc = new GlideRecord('cmn_location');

              if (loc.get(buildingid)) {

                      var campus = new GlideRecord('cmn_location');

                      if (campus.get(loc.parent)){

                              var json = new JSON();

                              var results = {

                                      "sys_id": campus.getValue("sys_id"),

                                      "name": campus.getValue("name")

                              };

                              return json.encode(results);

                      }

              } else {    

                      return null;

              }            

      }

});

You might also like