Creating a MID server Script Include

Let's create a new record that mirrors the first Script Include in Chapter 3Server-Side Control.

  1. Navigate to MID Server > Script Includes. Click New, fill out the fields below, and Save.
    • Name: SimpleAdd
    • Script:
var SimpleAdd = Class.create();
SimpleAdd.prototype = {
initialize: function (n) {
ms.log('Creating new object');
this.number = (n - 0) || 0;
},
increment: function () {
this.number++;
ms.log(this.number);
return this;
},
type: 'SimpleAdd'
}

This code is almost identical to a typical Script Include. The only difference is that the logging is done with the ms global variable instead of gs.

The script has two functions. One is run when the object is created and sets the number variable. The ...

Get ServiceNow: Building Powerful Workflows now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.