Docs‎ > ‎Reference‎ > ‎

SysUtility

SysUtility is a JavaScript object that offers access to several useful services:

SysUtility.getResource(resourceName, settings)

This will retrieve the value of the specified resource, using the settings in the second parameter, which must be an object that may have the following properties:

  • filter: an object with the desired filter(s) for each resource
  • order: an object with the desired sorting order(s) for each resource
  • pagesize: the maximum number of row per resource level
  • offset: how many records to skip from the top resource
  • chunksize: TBD
Note that the return value is an object - the JSON object returned by the call. A typical example:


var parts = SysUtility.getResource("Parts", {filter: {Parts: "price < 100"}, order: {Parts: "price desc"}});


Please note that, due to some internal limitations, if the resource is a view, then you must qualify it, and the filter(s), e.g. :

var parts = SysUtility.getResource("nw:Customer Orders", {filter: {"nw:Customer Orders": "price < 100"}});

If the resource you are invoking is a stored procedure resource, then you can pass parameters as follows:

var orders = SysUtility.getResource("nw:MyProc", {procArgs: {empName: "Doe", amount: 123.45}});

Invoking other services

You can also invoke other RESTful services from business logic or row events.
In these calls (restGet, restPut, restPost, restDelete, described below), you pass the following parameters:

params: an object containing the parameters to the call. 

For example:

var params = {
    name: "Acme",
    country: "Elbonia"
};
var json = SysUtility.restGet('http://rest.example.com/myservice', params);
var resultObject = JSON.parse(json);

This is equivalent to adding these parameters to the URL, e.g.:

http://rest.example.com/myservice?name=Acme&country=Elbonia

You should generally avoid putting parameters directly in the URL because they need to be properly encoded -- it is much easier to pass them in as an object.


settings: an object containing the various settings for the call. Currently, the only setting supported is headers:

SysUtility.restGet('http://rest.example.com/myservice',
   {name: 'Acme', country: 'Elbonia'},
   {headers: {
      "Authorization" : "Basic base64string",
      "Cache-Control" : "no-cache"
   }
});


requestData is a JavaScript object - it will be converted to JSON before being sent. These methods currently do not support sending non-JSON data, please contact Espresso Logic if you need this feature.

  • SysUtility.restGet(url, params, settings)
returns a stringified version of the result of the GET to the specified url.

  • SysUtility.restPut(url, params, settings, requestData)
returns a stringified version of the response of a PUT to the specified url using the requestData

  • SysUtility.restPost(url, params, settings, requestData)
returns a stringified version of the response of a POST to the specified url using the requestData

  • SysUtility.restDelete(url, params, settings)
returns a stringified version of the response of a DELETE to the specified url.


For more info on HTTP headers, see Wikipedia Entry to for HTTP Headers
Comments