Developing APIs‎ > ‎Extensibility‎ > ‎

The SysUtility Object

You can access the following services using the SysUtility JavaScript object:

getResource Service

The getResource service retrieves the value of the specified resource:

SysUtility.getResource(resourceName, settings)

This service retrieves the value using the settings in the second parameter, which must be an object that may have the following properties:

  • filter, sysfilter, userfilter. An object with the desired filter(s) for each resource. Use aliased (not table) attribute names for filter and sort.
  • order, sysorder, userorder. An object with the desired sorting order(s) for each resource.
  • pagesize. The maximum number of row per resource level.
  • offset. The number or records to skip from the top resource.
  • chunksize. Determines how many rows to include in a single SQL query for a sub-resource batch.
Note: If you have disallowed free-form filters, only the sysfilter, userfilter, sysorder, and userorder properties work with SysUtility calls.

For more information about how to disallow free-form filters, see Manage your API Project.

The return value of the getResource service is an object array, which is the JSON object returned by the call. The following is a typical example:

var parts = SysUtility.getResource("Products", {sysfilter: "less(price:100)", sysorder: "(price:desc)"});
for(var i = 0 ; i < parts.length ; i++){
log.debug(JSON.stringify(parts[i]));
}

For more information about how to use the JSON object, see JavaScript.

You can also pass an array of string to sysfilter or sysorder:

sysfilter: ["less(...)", equal(...),"greater(...)"]

You can reference a sub-resource(s) where the price of the product is less than 100 is a sub-resource or Customer.Orders.Product using '.' dot notation:

'sysfilter.Customer.Orders.Product': 'less(price:100)'

If the resource is a view, qualify it and the filter(s), for example:

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}});

rest<verb> - Get, Put, Post, Delete

You can invoke other RESTful services from business logic or row events using the restGet, restPut, restPost, and restDelete methods. In these calls, you pass the URL, parameters, settings, and request data.

For example:

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

params: An object containing the parameters to the call. 

This is equivalent to adding these parameters to the URL, for example:

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

Note: Avoid putting parameters directly in the URL because they need to be properly encoded. Pass them in as an object.

The settings object contains the various settings for the call. The header setting is supported:

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

The requestData JavaScript object is converted to JSON before being sent. You can send only JSON data using these methods.

restGet Method

The SysUtility.restGet(url, params, settings) method returns a stringified version of the result of a GET to the specified URL:

var result = SysUtility.restGet(url, params, settings),
var myJson = JSON.parse(result);

restPut Method

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

var result = SysUtility.restPut(url, params, settings, requestData),
var myJson = JSON.parse(result);

restPost Method

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

var result = SysUtility.restPost(url, params, settings, requestData),
var myJson = JSON.parse(result);

restDelete Method

The SysUtility.restDelete(url, params, settings) method returns a stringified version of the response of a DELETE to the specified URL:

var result = SysUtility.restDelete(url, params, settings),
log.debug(result);
var myJson = JSON.parse(result);

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

Debugging rest<verb>

Before coding the previous calls, verify your URL, headers, etc. using Rest tools such as Postman. The following image shows an example:
Error Handling

You can test the results of the response on the Manage, Rules page. The following image shows how to test the results on this page:

A log is generated on the Analyze, Logs page. The following image shows the log on this page: