SCRIPT Component

Using the SCRIPT component.

The SCRIPT component allows you to write flow logic using server-side JavaScript. The result of the script logic has to be returned via a special build-in result object.

This simple example shows manipulating a string declared inside the component. Click Run script to run the script and see the result (click on the Result tab in the code widget):

var str = "api key";
result = str.toUpperCase();
"API KEY"

The SCRIPT component also has access to all Components Data objects. Let's look at an example using one of these objects.

Let's say the API Express service defined a request parameter called count. Inside the SCRIPT component, you want to check its value and return an appropriate message.

var count = PARAMS.QUERY.count;
if (count < 10) {
    result = {
        "msg": "Inventory low."
    };
} else {
    resutl = {
        "msg": "Inventory OK."
    };
}
{
  "msg": "Inventory OK."
}
{
  "msg": "Inventory low."
}

Samples

This section has a number of samples using the SCRIPT component:

* Video: Learn How to Add Custom Logic with the SCRIPT Component.