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, sysfilter, userfilter: an object with the desired filter(s) for each resource
  • order, sysorder, userorder: 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: determines how many rows to include in a single SQL query for a sub-resource batch  
If the API Properties/Settings has disabled the use of filter/sort - only sysfilter, userfilter, sysorder, and userorder will work with SysUtility calls.

Note that the return value of getResource is an object array - the JSON object returned by the call. 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]));
}

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

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

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

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

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 CA Technologies if you need this feature.

  • SysUtility.restGet(url, params, settings)
returns a stringified version of the result of the GET to the specified url.
var result = SysUtility.restGet(url, params, settings),
var myJson = JSON.parse(result);

  • SysUtility.restPut(url, params, settings, requestData)
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);

  • SysUtility.restPost(url, params, settings, requestData)
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);

  • SysUtility.restDelete(url, params, settings)
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