Thank you for your feedback.
Form temporarily unavailable. Please try again or contact docfeedback@servicenow.com to submit your comments.
Versions
  • London
  • Kingston
  • Jakarta
  • Istanbul
  • Helsinki
  • Geneva
  • Store
Close

Widget Client Script

Widget Client Script

Use the Client Script to handle all the client-side logic and template binding for your widget.

This information is for pro code users. Only make changes to client scripts if you have a firm understanding of AngularJS.

Every widget is an Angular directive; you can use the Client Script to define the controller for that directive. The Client Script is the controller already linked to the widget. For example, the stock widget uses the following client script:

function() {    
    var c = this;
    c.update = function() {
        c.data.price = false;
        c.server.get({symbol:c.data.symbol}).then(function(r) {            
            c.data.price = r.data.price;            
        });
    }
}
Table 1. Client Script properties
Property Description
this.server.get([Object]) Calls the server and sends custom input. Returns Promise.
this.server.update() Calls the server and this.data is automatically send to server side. Returns Promise.
this.server.refresh() Calls the server and automatically replaces the current options and data from the server response. Returns Promise.

A promise represents the eventual result of an asynchronous operation. Promises are objects or functions that usually contain a then method, which subscribes to this specification. For more information on promises, see https://promisesaplus.com/ or the AngularJS documentation site.

Because catalog client scripts need to be compatible with the mobile API, some already existing catalog client scripts may not work in Service Portal.