Scripting
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.
- DecEnvNumber
- GetEnvNumber
- GetEnvNumberDef
- GetEnvVar
- GetEnvVarDef
- GetEnvVarDefT
- IncEnvNumber
- MatchingEnvVar
- ResetEnvVar
- ResetEnvVars
- SetEnvNumber
- SetEnvVar
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
- DateTimeToJulianStr
- DateTimeToTandemJulianStr
- DateTimeToUnix
- DateTimeToXml
- FormatDate
- NowAsStr
- SiebelNowAsStr
- SiebelTodayAsStr
- StrToDate
- StrToDateTime
- TodayAsStr
- UnixToDateTime
String functions
- GenerateGUID
- ifthen
- Latin1Str
- LowercaseStr
- NameCaseStr
- NewLine
- NumberToStr
- ResolveAliasses
- SeparatedString
- SeparatedStringN
- SeparatedStringT
- SqlQuotedStr
- StrHasRegExpr
- StrMatchesRegExpr
- StrOfChar
- SubStr
- UppercaseStr
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
- ExecuteOperationScript
- ExecuteScript
- ExecuteScriptLater
- Exit
- OperationCount
- PromptReply
- PromptRequest
- RaiseError
- RaiseHttpFault
- RaiseSoapFault
- RaiseWsdlFault
- RequestOperation
- RequestOperationLater
- ResetOperationCounters
- ReturnString
- SendOperationRequest (depricated)
- SendOperationRequestLater (depricated)
- Sleep
Logging
- AddRemark
- ClearLogs
- ClearSnapshots
- CreateJUnitReport
- CreateSnapshot
- CreateSummaryReport
- LogsFromRemoteServer
- ShowMessage
Design
All functions
- AccordingSchema
- AddRemark
- AssignAnyType
- Assigned
- AsXmlString
- ClearLogs
- ClearSnapshots
- CreateJUnitReport
- CreateSnapshot
- CreateSummaryReport
- DateTimeToJulianStr
- DateTimeToTandemJulianStr
- DateTimeToUnix
- DateTimeToXml
- dbLookUp
- DecEnvNumber
- ExecSql
- ExecuteOperationScript
- ExecuteScript
- ExecuteScriptLater
- Exit
- FetchDefaultDesignMessage
- FormatDate
- GenerateGUID
- GetContext
- GetEnvNumber
- GetEnvNumberDef
- GetEnvVar
- GetEnvVarDef
- GetEnvVarDefT
- HostName
- ifthen
- IncEnvNumber
- Latin1Str
- LengthStr
- LogsFromRemoteServer
- LowercaseStr
- MatchingEnvVar
- MD5
- MessageName
- MessageOfOperation
- MessagingProtocol
- NameCaseStr
- NewDesignMessage
- NewLine
- NowAsStr
- NumberToStr
- Occurrences
- OperationCount
- OperationName
- PopulateFromXmlString
- PromptReply
- PromptRequest
- PushOperationToRemoteServer
- PushProjectToRemoteServer
- RaiseError
- RaiseHttpFault
- RaiseSoapFault
- RaiseWsdlFault
- Random
- RegExprMatch
- RegExprSafeStr
- RemoveDesignMessages
- ReplyAsText
- RequestAsText
- RequestOperation
- RequestOperationLater
- ResetEnvVar
- ResetEnvVars
- ResetOperationCounters
- ResolveAliasses
- ReturnString
- Rounded
- SaveLogs
- SendOperationRequest
- SendOperationRequestLater
- SeparatedString
- SeparatedStringN
- SeparatedStringT
- SetContext
- SetEnvNumber
- SetEnvVar
- SHA1
- ShowMessage
- SiebelNowAsStr
- SiebelTodayAsStr
- Sleep
- SqlQuotedStr
- SqlSelectResultRow
- StrFromClipboard
- StrHasRegExpr
- StrMatchesRegExpr
- StrOfChar
- StrToDate
- StrToDateTime
- StrToFile
- StrToNumber
- SubStr
- SwiftNumberToStr
- SwiftStrToNumber
- Tab
- TodayAsStr
- UnixToDateTime
- UppercaseStr
- UserName