The SysUtility Object

You can send REST requests and access services, such as retrieving a resource or invoking another REST service, using the methods that are included with the
SysUtility
JavaScript object. Use this object in the JavaScript code for custom endpoints, resources, listeners, and event handlers.
You can also use the SysUtilityV2 object. This object includes the same methods as the SysUtility object, but unlike SysUtility, it always returns a JavaScript object. The SysUtilityV2 object does not require that you parse JSON strings to JavaScript objects by using the JSON.parse() method. Using this method can lead to loss of precision when dealing with BigInteger and BigDecimal numbers.
This object includes the following methods:
2
databaseNowDeferred() Method
You can call the
databaseNowDefferred()
method to return an object and assign it to an entity resource attribute. The object represents the current date, time, or timestamp on the database server at the instant the resulting SQL is executed on the database server. The
databaseNowDeferred()
method is aware of the underlying database and emits the correct SQL fragment appropriate for the specific datatype and database in use.
This method uses the following syntax:
SysUtility
.databaseNowDeferred()
You can also return an object and assign it to an entity resource attribute by calling the
sqlSnippetDeferred()
method, using the database-specific SQL syntax to match the datatype.
For more information about this method, see the "sqlSnipperDeferred() Method" section.
You can add this method to the code for event rules, pre-insert event rules, and formula rules.
Example:
var databaseTimestamp = SysUtility.databaseNowDeferred();row.last_updated = databaseTimestamp
For more information:
findEntities() Method
You can call the
findEntities()
method to find a SQL table data from a table endpoint of the current API. You can add this method to the code for GET or PUT/POST resource events to return SQL entity (table or view) data. Because GET or PUT/POST resource events use the response that this method returns, the response does not support pagination.
This method uses the following syntax:
SysUtility.
findEntities
(entity, param)
The
B2B Northwind
API sample includes the
ShipperAPIDefHiddenVirtuals
resource that illustrates the "fuzzy" foreign key lookup scenario. The GET event for this resource includes this method to perform the lookup and then uses the
virtuals
variable in the GET event to set the value of the
ShipperMemo
virtual resource attribute.
For more information about using "fuzzy" foreign keys in GET events, see Manage Resource Attributes.
For more information about how to create PUT/POST events, see Manage Resource Events.
The entity Parameter
Specify the table name in the
entity
parameter.
The param Map Parameter
You can pass in the
param
map parameter with conditions used as SQL clauses. You can pass the following attributes into the
param
map parameter:
Attribute Name
Description
columns
An array of column names that this method returns. Specify this attribute to have the method returns specific columns.
Type:
string array
Required:
No
whereClause
The
SQL WHERE
clause using to select rows from the SQL table.
Type:
string
Required:
No
The syntax for the
whereClause
attribute must be database-specific to the data source.
orderByClause
The
SQL ORDER BY
clause using to order the rows from the SQL table.
Type:
string
Required:
No
The syntax for the
whereClause
attribute must be database-specific to the data source.
usingValues
Name-value pairs for the
WHERE
clause used to filter rows from the SQL table. Use this attribute to find an exact match from the table.
Type:
JSON object
Required:
Yes
You can use the
whereClause
and/or the
usingValues
attributes together.
Example:
The following example finds rows for the
product
table:
// columns, whereClause, and orderByClause are all optional.
// The usingValues is a JSON object of name value pairs.
var productNumber = row.product_number;
var params = {
columns: [
'name',
'price',
'product_number',
'full_image'
],
whereClause: null,
orderByClause: null,
usingValues: {
product_number: productNumber
};
var products = SysUtility.
findEntities
("demo:product", params);
var product = null;log.debug(JSON.stringify(products, null, 2));
if (products && products.length > 0 ) {
product = products[0];
}
return product;
getApiInfo() Method
You can retrieve information about an API and adjust the behavior dynamically using the following
getApiInfo()
method in your JavaScript code:
var apiinfo = SysUtility.
getApiInfo()
;log.debug(apiinfo.urlFragment + " " + apiinfo.name);
This method returns an object with information about the current API.
getBytes() Method
You can convert JavaScript or a Java object into a Java byte array using the
getBytes()
method in your JavaScript code:
SysUtility.
getBytes
(message, charset)
This method can have the following parameters:
  • message
    . The value for this parameter must be a JavaScript or Java object.
  • charset
    . For String types, the
    charset
    parameter is the string representation of the character set used to encode the string. Otherwise, set this property to
    null
    .
Layer7 Live API Creator
stringifies JavaScript types before converting them using the standard
JSON.stringify()
JavaScript method. The default character set used for conversion is UTF-8.
Example: Gets Bytes from a JavaScript Object
The following example gets bytes from a JavaScript object:
var javascriptObject = {product : "Layer7 Live API Creator", version : 5.4.00};var asBytes = SysUtility.getBytes(javascriptObject,null);
Example: Gets Bytes from a Message String Encoded with UTF-16
The following example gets bytes from a message string encoded with UTF-16:
var messageAsString = message.toString();var asBytes = SysUtility.getBytes(message,"UTF-16"); SysUtility.publishMessage("MyConnection","MyTopic",asBytes,null);
getConnection() Method
You can have
Layer7 Live API Creator
return the
connection
JavaScript object representing the connection that is identified by the string argument name using the
getConnection()
method in your JavaScript code.
This method uses the following syntax:
SysUtility.
getConnection
("<connection name>")
The JavaScript object that
Layer7 Live API Creator
returns is dependent on the connection type (MQTT, KafkaConsumer, or KafkaProducer). For more information about the
connection
JavaScript object for MQTT connections, see the "The connection JavaScript object (MQTT)" section.
Example
:
The following example gets an MQTT connection and uses it in your code:
var connectionJSObject = SysUtility.
getConnection
("MyMQTTConnection");var javaMQTTClientObject = connectionJSObject.mqttClient;// Checking if you have the connectionif(javaMQTTClientObject.isConnected()){log.debug("I still have connection");}
The connection JavaScript Object (MQTT)
MQTT connections are encapsulated in the
connection
JavaScript object of the following form:
{mqttClient: < An instance of org.eclipse.paho.client.mqttv3.MqttClient >, persistence: < An instance of org.eclipse.paho.client.mqttv3.persist.MemoryPersistence >, startupEnv: < A JavaScript object containing objects that are specific to MQTT. >}
For more information:
getExtendedPropertiesFor() Method
You can retrieve the extended properties for a resource and adjust the behavior dynamically using the following
getExtendedPropertiesFor()
method in your JavaScript code:
SysUtility.
getExtendedPropertiesFor
(apiVersionName, name)
The
apiVersion
property is optional. If you omit this property or it is null,
Layer7 Live API Creator
uses the version of the API in the request. This call returns a JavaScript object.
Example:
var extendedProperties = SysUtility.get
ExtendedPropertiesFor
("v1", "AllCustomers");if (extendedProperties && extendedProperties.MyExtension) { out.printIn("v1/AllCustomers has an extendedProperties 'MyExtension' value of ", JSON.stringify(extendedProperties.MyExtension));}
For more information about how to access the extended properties for a resource using this method, see Manage the Extended Properties for Resources.
getFunction() Method
You can retrieve the value of a specified top-level function using the following
getFunction()
method in your JavaScript code:
SysUtility.
getFunction
(functionName, parameterList)
The
parameterList
parameter is optional. This parameter is an object with the desired list of parameter names in JavaScript format.
Example:
var sum = SysUtility.
getFunction
("addNumbers", {parm1: 10, parm2: 20});log.debug(sum);
For more information:
  • About how to use the JSON object, see JavaScript.
  • About functions, including how to call functions from within API Server using this method, see Manage Functions.
getHostName() Method
You can retrieve the server host name using the
getHostName()
method.
This method does not always return the results that you expect, since servers can have multiple names. This method calls the
InetAddress.getLocalHost().getHostName()
Java method. If this Java method fails, it uses the first open interface from the
NetworkInterface.getNetworkInterfaces()
method.
Best Practice:
Test this method to ensure that it returns what you expect.
getHostNameAddress() Method
You can retrieve the server IP address using the
getHostAddress()
method.
This method does not always return the results that you expect, since servers can have multiple interfaces. This method calls the
InetAddress.getLocalHost().getHostName()
Java method. If this Java method fails, it uses the first open interface from the
NetworkInterface.getNetworkInterfaces()
method.
Best Practice:
Test this method to ensure that it returns what you expect.
getProcedure() Method
You can retrieve the value of a stored procedure using the following
getProcedure()
method in your JavaScript code:
SysUtility.
getProcedure
(procedureName, argsList)
The
argsList
parameter is optional. This parameter is an object with the desired list of arguments in JavaScript format. This method returns a JSON object.
Example:
var procresp = SysUtility.
getProcedure
("demo:get_employee", {given_employee_id: 1, plus_one: 2});log.debug(JSON.stringify(procresp,null,2));
For more information:
getResource() Method
You can retrieve the value of the specified resource using the following
getResource()
method:
SysUtility.
getResource
(resourceName, settings)
This method returns a stringified version of the response to a resource. This service operates on your resources in the API. The return value of this method is an object array, which is the JSON object that is returned by the call.
You can retrieve a string by calling the
getResourceAsString()
method or by stringifying the result.
For more information about this method, see the "getResourceAsString() Method" section.
This method retrieves the value set for the
settings
parameter. The value must be an object that can have the following properties:
  • filter
    ,
    sysfilter
    ,
    userfilter
    . An object with the desired filters for each resource.
    Use aliased attribute names (not table attribute names) for
    filter
    and
    sort
    .
    By default, these properties work with
    SysUtility
    calls. By default, you can only use named filters and named filters (the
    sysfilter
    and
    userfilter
    properties) with
    SysUtility
    calls. For more information about how to turn on regular filters, see Structured Filters.
  • order
    ,
    sysorder
    ,
    userorder
    . An object with the desired sorting orders for each resource.
    By default, these properties work with
    SysUtility
    calls. By default, you can only use named sorts (the
    sysorder
    and
    userorder
    properties) with
    SysUtility
    calls. For more information about how to turn on regular sorts (and sorts), see Structured Sorts.
    For more information about using named sorts, see Structured Sorts.
  • pagesize
    . The maximum number of rows per resource level.
  • offset
    . The number or records to skip from the top resource.
  • chunksize
    . Determines the number of queries
    Layer7 Live API Creator
    executes to return the rows for table-based subresources.
  • params
    . An object containing name/value pairs for parameters to, for example, SQL resources. The name must start with 'arg_'.
The
settings
parameter typically specifies your filter criteria (
filter
,
sysfilter
,
userfilter
), for example:
var settings = {sysfilter: "equal(OrderID:" + row.OrderID + ")" ,"sysfilter.SupplierAlert.Order_DetailsList.Product.Supplier": "equal(CompanyName: '" + "Pavlova, Ltd." + "')" };
You can specify the
pagesize
,
offset
,
chunksize
, and
params
properties in the
settings
parameter, for example:
The values for the following properties are typically defaulted. They are not required, but shown for reference in this example.
var details = { filter: "name like 'ABC%', order: "name asc", pagesize: 20, offset: 0, chunksize: 10, params: {arg_minSalary: 90000, arg_province: 'BC'} };
The
B2B Northwind
API includes the
SupplierAlert
resource that matches the API agreement with the Pavlov supplier, as follows:
var supplierReport_response = SysUtility.getResource("SupplierAlert", options);
For more information about the B2B sample, see B2B API Sample.
For more information:
Example:
var parts = SysUtility.
getResource
("main: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 as the value for
sysfilter
or
sysorder
, for example:
sysfilter: ["less(total: 100)", "equal(name: 'Acme')"]
You can reference a subresource where the price of the product is less than 100 as a subresource 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, 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}});
getResourceAsString() Method
You can retrieve a resource instance from the current API, with the specified filter parameters, using the specified settings, using the following
getResourceAsString()
method:
SysUtility.
getResourceAsString
(resourceName, settings)
This call returns a string object.
Example:
var prodResp = SysUtility.getResourceAsString("nw:Products", {sysfilter: "less(price:100)", sysorder: "(price:desc)"});var parts - JSON.parse(prodResp);for (var i in parts) { log.debug(JSON.stringify(parts[i], null, 2));}
getTeamSpaceInfo() Method
You can retrieve information about a TeamSpace and adjust the behavior dynamically using the following
getTeamSpaceInfo()
method in your JavaScript code:
var teamspaceinfo = SysUtility
.getTeamSpaceInfo()
;log.debug(teamspaceinfo.urlFragment + " " + teamspaceinfo.name + " " + teamspaceinfo.isActive);
This method returns an object with information about the current TeamSpace.
postToFunction() Method
The
postToFunction()
method posts the payload to a top-level function and returns a JavaScript JSON object.
This method uses the following syntax:
SysUtility.
postToFunction
(functionName, parameterList, payload)
The
parameterList
parameter is optional. This parameter is an object with the desired list of parameter names in JavaScript format.
Example:
var sortedArray = SysUtility.postToFunction("sortWithPOST", {orderby: "desc"},{"fruits": ["Banana", "Orange", "Apple", "Mango"]});log.debug(sortedArray); return JSON.parse(sortedArray);
For more information:
  • About how to use the JSON object, see JavaScript.
  • About functions, including how to call functions from within API Server using this method, see Manage Functions.
processHTTPInParallel() Method
You can have
Layer7 Live API Creator
call multiple HTTP requests in parallel. The
processHTTPInParallel()
method optimizes your API by creating separate threads to call the HTTP service requests, and then it returns and array of JSON responses. You can iterate through the responses to perform more processing or API mashups before returning the response to the client.
This method uses the following syntax:
SysUtility.
processHTTPInParallel
(httpRequestArray)
The httpRequestArray Parameter
The
httpRequestArray
parameter is an array of JSON objects that you can pass into the
processHTTPInParallel()
method. You can pass in the following attributes into each JSON object:
Attributes and example
Attribute Name
Description
verb
The HTTP verb that the caller uses to call the HTTP request.
Type:
String
Required:
Yes
url
The URL endpoint for the HTTP request.
Type:
String
Required:
Yes
timeout
The maximum time (in milliseconds) allocated for calling the URL endpoint.
Type:
Integer
Required:
Yes
params
The parameters to the HTTP request call. This is equivalent to adding these parameters to the URL.
Type:
JSON object
Required:
No
json
The JSON payload to be passed in to a PUT/POST/DELETE request.
Type:
JSON object
Required:
No
settings
The headers for the HTTP request call.
Type:
JSON object
Required:
No
Example: 
//JSON array of HTTP Requests
var httpRequestArray = [
{
verb: "GET",
url: "http://localhost:8080/rest/default/demo/v1/demo:customer",
settings: {
headers: {
"Authorization": "CALiveAPICreator demo_full:1"
} },
timeout: 100000
}, {
verb: "GET",
url: "http://localhost:8080/rest/default/demo/v1/gcd",
params: {
n1: 5,
n2: 25
},
settings: {
headers: {
"Authorization": "CALiveAPICreator demo_full:1"
}
},
timeout: 1000
}
];
var result = SysUtility.processHTTPInParallel(httpRequestArray);
Evaluate the Return from the processHTTPInParallel() Method
The
processHTTPInParallel()
method returns an array of results. For each result, you can use the following methods and properties to examine the response for each HTTP request:
Methods and properties
getResponseBytes Method
The
getResponseBytes()
method returns the response bytes for the HTTP request call. 
getResponseHeader Method
The
getResponseHeader()
method return the HTTP response headers.
getStartTime Property
The
getStartTime
property returns the timestamp in milliseconds when the HTTP request was triggered.
getEndTime Property
The
getEndTime
property returns the timestamp in milliseconds when the HTTP request was completed.
ErrorCode Property
The
ErrorCode
property returns the HTTP error code.
ErrorMessage Property
The
ErrorMessage
property returns the HTTP error message.
The following example shows how you can evaluate the result for each HTTP Request call.
Example:
var response = [];
for (var j in result) {
// Convert the response object to a JSON
var resultJson = JSON.parse(result[j].toString());
if (resultJson.response) {
try {
var temp = JSON.parse(resultJson.
response
);
response.push(temp);
log.debug("Response bytes: " + resultJson.
getResponseBytes()
);
log.debug("Response headers: " + resultJson.
getResponseHeader()
);
log.debug("Request start time: " + resultJson.
StartTime
);
log.debug("Response end time: " + resultJson.
EndTime
);
}
}
else {
response.push(
{
errorCode: resultJson.
errorCode
,
errorMessage: resultJson.
errorMessage
}
);
}
}
publishMessage() Method
You can publish a message to a topic in the MQTT or Kafka broker using the following
publishMessage()
method in your JavaScript code:
SysUtility.
publishMessage
(connectionName,topic,message,options)
This method can have the following parameters:
  • connectionName
    . The value for this parameter must be a string that represents the connection to use to connect to the broker.
  • topic
    . The value for this parameter must be a string that represents the topic you are publishing to.
  • message
    . The value for this parameter must be a JavaScript or Java object.
  • options
    . The value for this parameter must be a JavaScript object. You can define the way
    Layer7 Live API Creator
    sends the message to the receiver by setting extra properties.
    The properties that you can set for the options parameter in the publishMessage() method depend on the connection type (MQTT or KafkaProducer).
    For more information:
Response:
A boolean response type is expected. If the message successfully publishes, the value of the variable is
true
.
Exception:
If there are errors during publishing, the method throws JSException. This object is a type of
java.lang.RuntimeException
and contains the following properties:
  • fileName
    . The value of this property is a String that represents the name of the JavaScript source file that caused the error. If unavailable, the value is blank.
  • lineNumber
    . The value of this property is a Number that represents the line number in the source file that caused the error. If unavailable, the value is -1.
  • stackString
    . The value of this property is a String that represents the JavaScript exception stack trace.
  • scriptFrames
    . The value of this property is an Array containing the stack frames that are related to the error.
Example: Publish a Text Message to an MQTT Broker
The following example publishes a text message to an MQTT broker:
var connectionName = "MyMQTTConnection";var topic = "ca/liveapicreator";var message = "Hello World";var options = null;// Publishing done below try { var publishStatus = SysUtility.publishMessage(connectionName,topic,message,options);} catch(e){ log.debug("Error during publishing. "+e);} if(publishStatus){ log.debug("Wohoo!. Message published to MQTT broker");}
Example: Publish a Text Message to an MQTT Broker that Includes the
options
Parameter
The following example publishes a text message to an MQTT broker that includes the
options
parameter:
var connectionName = "MyMQTTConnection";var topic = "ca/liveapicreator";var message = "Hello World - IMPORTANT";// Set MQTT options.var opts = {"qos":2,"retained":true};// Publishing done below try { var publishStatus = SysUtility.publishMessage(connectionName,topic,message,opts);} catch(e){ log.debug("Error during publishing. "+e);} if(publishStatus){ log.debug("Message published to MQTT broker with Quality of Service as 2 and Retained as TRUE.");}
Example: Publish a Text Message to a Kafka Broker
The following example publishes a text message to a Kafka broker:
var connectionName = "KafkaProducerConnection";var topic = "MyTestTopic"; var options = {key: 'myKey',partition: 0}; var message = "My test Kafka message"; try{ var response = SysUtility.publishMessage(connectionName, topic, message, options);} catch(e){ log.debug("Error during publishing. "+e);} if(response.isSuccess) { log.debug(JSON.stringify(response)); log.debug("Publish Message to KafkaProducerConnection"); }
Properties for the options Parameter (MQTT)
You can set the following properties as part of the
options
parameter in the
publishMessage
function for MQTT connection types:
Properties for the options Parameter (MQTT)
qos
Defines the Quality of Service (QOS) at which
Layer7 Live API Creator
should deliver the message.
Value:
0, 1 or 2
Default:
0
Required:
No
retained
Determines whether you want the server to retain the message.
Values:
true or false
Default:
false
Required:
No
Properties for the options Parameter (Kafka)
The Kafka producer is responsible for choosing which message to assign to which partition within the topic. It is the client’s responsibility to decide the partition to which to send the message. You can set the following properties as part of the options parameter in the publishMessage function for the KafkaProducer connection type.
Properties for the options Parameter (Kafka)
partition
Defines the partition in which you want to publish this message.
Value:
number
Default:
0
Required:
No
key
Determines the key that you want to use to define the message.
Values:
string
Default:
null
Required:
No
rest<verb> - Get, Put, Post, Patch, Delete() Methods
You can invoke other RESTful services from business logic or from resource events using the following methods:
SysUtility.
restGet
(url, params, settings)
SysUtility.
restPut
(url, params, settings, requestData)
SysUtility.
restPost
(url, params, settings, requestData)
SysUtility.
restPatch
(url, params, settings, requestData)
SysUtility.
restDelete
(url, params, settings)
In these calls, you pass the URL, parameters, settings, and request data.
For more information about resource events, see Manage Resource Events.
restGet() Method
You can have
Layer7 Live API Creator
return a stringified version of the result of a GET to the specified URL using the
SysUtility.restGet()
method in your JavaScript code:
var result = SysUtility.
restGet
(url, params, settings);var myJson = JSON.parse(result);
restGet
Example:
var params = { name: "Acme", country: "Elbonia" }; var json = SysUtility.
restGet
('http://rest.example.com/myservice', params); var resultObject = JSON.parse(json);
The
params
object contains 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
Do not add parameters directly in the URL. Properly encode parameters and pass them in as an object.
The optional
settings
parameter contains the various settings for the call. It can have the following properties:
  • The
    headers
    setting. Add this setting to the call as HTTP headers. It must include name/value pairs.
  • The
    proxy
    setting. This setting ensures that the HTTP call is made using the specified HTTP proxy server. It can include the following properties:
    • hostname
      : Set the value to the host name of the HTTP proxy server.
    • port
      : Set the value to the port number for the HTTP proxy server.
    • username
      : To provide authentication information, set the value to the username for the HTTP proxy server.
    • password
      : To provide authentication information, set the value to the password for the HTTP proxy server.
restGet Example:
SysUtility.
restGet
('http://rest.example.com/myservice',
{name: 'Acme', country: 'Elbonia'},
{headers: {
Authorization : "Basic <base64string>",
"Cache-Control" : "no-cache"
},
proxy: {
hostname: "proxy.example.com",
port: 8282
username: "admin2",
password: "password2"
}
});
Layer7 Live API Creator
converts the
requestData
JavaScript object to JSON before sending it. You can send only JSON data using these methods.
restPut() Method
You can have
Layer7 Live API Creator
return a stringified version of the response of a PUT to the specified URL using the
SysUtility.restPut()
method and the
requestData
JSON object.
You can obtain the
requestData
JSON object using the
SysUtility.restGet()
method.
var result = SysUtility.
restPut
(url, params, settings, requestData); // requestData is a JSON object var myJson = JSON.parse(result);
restPost() Method
You can have
Layer7 Live API Creator
return a stringified version of the response of a POST to the specified URL using the
SysUtility.restPost()
method and the
requestData
JSON object.
You can obtain the
requestData
JSON object using the
SysUtility.restGet()
method.
var result = SysUtility.
restPost
(url, params, settings, requestData); var myJson = JSON.parse(result);
restPost Example:
The following example is from the B2B sample:
var settings = { headers: { Authorization: "CALiveAPICreator supplier:1" }}; var pavlov_response = SysUtility.
restPost
(url, null, settings, supplierReport_response);
Layer7 Live API Creator
converts the
requestData
JavaScript object to JSON before sending it. You can send only JSON data using these methods.
restPatch() Method
You can have
Layer7 Live API Creator
return a stringified version of the response of a PATCH to the specified URL using the
SysUtility.restPatch()
method and the
requestData
object.
Layer7 Live API Creator
converts the
requestData
JavaScript object to JSON before sending it. You can send only JSON data using these methods.
Layer7 Live API Creator
treats the PATCH verb like a PUT. Do not use this method against an API that you created using
Layer7 Live API Creator
.
Example:
var url = "https://api.acme.com/myApi/Widgets/42";var settings = { headers: { "X-ACME-Token": "ABC123" }};var requestData = {description: "Updated value here"}; var response = SysUtility.
restPatch
(url, null, settings, requestData);
restDelete() Method
You can have
Layer7 Live API Creator
return a stringified version of the response of a DELETE to the specified URL using the
SysUtility.restDelete()
method in your JavaScript code:
var result = SysUtility.
restDelete
(url, params, settings); log.debug(result); var myJson = JSON.parse(result);
The
requestData
JavaScript object is optional.
Layer7 Live API Creator
examines only the
headers
id. It ignores all other ids:
var settings = { "headers" : { "Authorization" : "Basic base64string", "Cache-Control" : "no-cache" } };
restGetBinary() Method
You can retrieve a byte array value for a specific data column using a
/data/
link in a URL and the following
restGetBinary()
method in your JavaScript code:
SysUtility.
restGetBinary
(resourceURL, params, settings)
Example:
var resourceURL = req.baseUrl + "/v1/demo:employee_picture/1/picture";
resourceURL = resourceURL.replace("rest","data"); var params = {}; var settings = { "headers": {"Authorization" : "CALiveAPICreator demo_full:1"}}; var byteArray = SysUtility.
restGetBinary
(resourceURL, params , settings); row.content = byteArray;// set the current row (type CLOB)
For more information about using data URLs, see Use Binary Data.
sqlSnippetDeferred() Method
You can have
Layer7 Live API Creator
return an object and assign it to an entity resource attribute in events and formula rules. This object represents a small portion of the database SQL that
Layer7 Live API Creator
executes as part of the SQL INSERT or UPDATE. This object can be a SQL function, a system, a user, a single-value select, such as
select max(val) from mytable
, or any other SQL that you can use as the value for the column:
SysUtility.
sqlSnippetDeferred
(timestamp)
You can add this method to the code for event rules, pre-insert event rules, and formula rules.
Example:
var databaseTimestamp = SysUtility.sqlSnippetDeferred('current timestamp(12)');return databaseTimestamp;
For more information: