Scripting

adding dynamics

apiUi offers a rich scripting engine with lots of built-in functions.
Scripts are either triggered by an event, such as an inbound service call, or triggered by an user action. Scripts that are triggered by an user are called User-scripts, scripts triggered by an event are the Operation-scripts.

User-scripts

Triggered by an user via the apiUi Scripts menu, triggered from another script by the ExecuteScript statement or via the api of apiUi/apiUiServer.
Access to operations is only possible for 'invoked' operations.

Operation-scripts

  • Inbound operations
    An inbound operation has one script that is executed after receiving the message and before sending the response. This allows you to give any response you like.
  • Outbound operations
    Outbound operations have two scripts.
    Before script
    Executed before sending the request. This allows you to fill in generated keys or timestamps or lookup data from a database.
    After script
    Executed after receiving the response. Makes it possible to do checks, do follow-up calls to other services or store data in a database.

Grammar

The grammar for the apiUi scripting language is described here in a kind of Backus–Naur form.
A special kind of statement is the for each. The for each statement has a code-block attached that is executed zero or more times.
The for each can be related to:

  • a function (e.g. SeparatedString)
  • a repeating element in a data structure
float ws.OrderAmount := 0;
for each rpy.Order.OrderLine ol
{
  ws.OrderAmount := ws.OrderAmount + StrToNumber (ol.Amount);  
}
  • an SQL-Select statement.
string ws.id;
string ws.name;
exec sql
  select id as :ws.id
       , name as :ws.name
  from Relation
  loop
  {
    ....  // do something with ws.id and ws.name
  }

State machine

Environment Variables

Each time an operation is executed, either due to incoming service calls or due to triggering of an outgoing one, such an operation starts with it's own fresh working area. Data is not shared among such activations. Environment variables offer a way to pass data from one operation to another. Each environment variable has a name and a value. Below you will find a list of built-in functions that set or get values for environment variables.

Regular expression

Database/SQL

You can access a database from apiUi scripts, either by embedded-sql statements, described here, or by functions.
Embedded-sql requires data to be mapped to data elements declared in the script.
Functions can work directly with datastructures from requests and replies.

Datetime functions

String functions

For each functions

A rather special script feature. Some functions have a list of strings as result and an codeblock attached that will be executed for each string in that list.

string ws.match;
for each RegExprMatch ('1234abcd333efg', '\d{2}') as ws.match do
{
  AddRemark (ws.match); // will show '12', '34' and '33'
}

Exceptions/Flow

Logging

All functions