Skip to main content

Running Custom Code

You can write JavaScript to interact with inputs and utility libraries, which is useful for adding custom logic to your application services. In service designer you can use the Run JavaScript Code node to write your custom code. Altogic automatically injects predefined list of utility libraries and node input values to the code execution context.

Accessing Node Inputs

You can access the values of object, list or value inputs in your custom JavaScript code using their names. Please note that, trigger link points added to this node as input will not be injected, since these linkpoints to do not have any values. In below example, a single users model object is passed to Run JavaScript Code node execution context as pickedValue. You can access the value of this input by using the ctx.pickedValue keyword in your custom code.

info

To access the input link point values in your custom code, you need to prefix the input names with ctx keyword (e.g., ctx.input, ctx.request).

Libraries

The Run JavaScript Node automatically imports the following utility libraries. You can use the keyword (e.g., moment, _, luxon) in your custom code to access the methods, classes and properties of these libraries.

LibraryKeywordDocsVersion
Altogicaltogichttps://www.altogic.com/clientv2.3.9
Axiosaxioshttps://www.npmjs.com/package/axiosv1.3.2
Decimal.jsdecimalhttps://www.npmjs.com/package/decimal.jsv10.2.0
Node Fetchfetchhttps://www.npmjs.com/package/node-fetchv2.6.9
Lodash_https://www.npmjs.com/package/lodashv4.17.21
Luxonluxonhttps://www.npmjs.com/package/luxonv3.2.1
Momentmomenthttps://www.npmjs.com/package/momentv2.29.4
info

You can directly use the await operator at your top level custom JavaScript code.