Commands reference¶
Script-A-Rest primarily includes commands to perform server calls, handle variables and orchestrate scripts. It also includes few other useful utilities and commands for performing assertions.
For information on how to start Test-A-Rest, have a look at the README.md
file. It also shows the possible command line arguments.
Commands¶
Commands are structured as one line with command and arguments with an optional JSON block.
Commands must begin at first position on a line. Command keywords are case insensitive. So Get SomeSvc.svc/SomeEntitySet
is the same as Get SomeSvc.svc/SomeEntitySet
.
Generally URLs, JSON payloads and variable references are case sensitive. So Get SomeSvc.svc/SomeEntitySet
is NOT the same as Get someSvc.svc/someentityset
.
Line comments can begin either with // or --. Comments be on first position on line. Comments after commands does not work.
Data types¶
Variables in Script-A-Rest are either basic types like string, int, double, boolean, DateTime or compound JSON types, i.e. containing an JSON object of any size and/or complexity.
JSON only supports string, numeric, boolean and null basic values. Complex JSON values are objects or arrays. Due to lack of JavaScript number precision, FndODataProvider and IFS Cloud Web Framework serializes numbers as strings (using IEEE 754 header). Script-A-Rest sends requests with IEEE 754 header and therefore any JSON values sent must be quoted as strings.
Example:
{
"pi": "3.14"
}
Available Commands¶
Server calls
Script variable handling
Calling other scripts
Other commands
Other references¶
- Expect Error on server calls
- Substitution handling
- Variable handling
- Connecting as different users
- Accessing configuration and command line parameters
- Expression evaluator
- Meta data
Post¶
Call URL with HTTP POST
Post
can be done conditionally by using then When
keyword.
(Also see the alternatives Action and Create)
Syntax¶
Post {ExpectFail} [URL path to service] {Using variableWithEtag} {Include [HeaderKey]} {Into [resultVariable] } {When [condition]}
JSON Object Body
Example
Post DockCodesHandling.svc/PurchaseDockCodes Into createResult1
{
"Contract": "1",
"DockCode": "DockA",
"Description": "Main Gate"
}
Into
section and variable is optional. If specified data returned from server will be placed here.
Post DockCodesHandling.svc/PurchaseDockCodes
{
"Contract": "1",
"DockCode": "DockA",
"Description": "Main Gate"
}
Using
section is optional and needed when calling actions requiring ETag, eg entity-bound actions. When Using
is used, Into
is mandatory
Post DockCodesHandling.svc/PurchaseDockCodes('DockA')/Ifsapp.DockCodesHandling.Release Using getResult1 Into createResult1
{
"Extraparams": "1",
}
Sometimes a call shouldn't be executed unless a certain condition is met.
Post DockCodesHandling.svc/PurchaseDockCodes('DockA')/Ifsapp.DockCodesHandling.Release Using getResult1 Into createResult1 When 1==1
{
"Extraparams": "1",
}
See ExpectFail on server calls for details about ExpectErrors
keyword
See Add Header to Http Request Example for details of adding headers to the request
Get¶
Call URL with HTTP GET verb.
Get
can be done conditionally by using then When
keyword.
Syntax¶
Get {ExpectFail} [URL path to service] Include [HeaderKey] Into [resultVariable] When [condition]
Examples (Assuming result of Get
command will be used in the following command(s), here CopyJson
.)
Example 1
Get DockCodesHandling.svc/PurchaseDockCodes(Contract='1',DockCode='A') Into getResult
CopyJson Description Using getResult Into response
Example 2
Get DockCodesHandling.svc/PurchaseDockCodes(Contract='1',DockCode='A') Into getResult When 1==1
CopyJson Description Using getResult Into response When 1==1
Example 3
ApplyJson Into getResult
{
}
Get IsoUnitsOfMeasureHandling.svc/IsoUnitSet(UnitCode='{$input.UnitCode}') Into getResult When 1==1
CopyJson UsedInAppl Using input into response When 1==1 && getResult.UserDefined==false
Into
section and variable is mandatory and data returned from server will be placed here.
When
section is optional. If specified and condition is met, data returned from the server will be placed in Into
variable.
See ExpectFail on server calls for details about ExpectErrors
keyword
See Add Header to Http Request Example for details of adding headers to the request
Query¶
Call URL with HTTP GET verb with options Select
, OrderBy
and Filter
Syntax¶
Query {ExpectFail} [URL path to service] {Select "Attr1,Attr2"} {OrderBy "Attr1 desc,Attr2"} {Filter With Json} Into [resultVariable] When [condition]
Select¶
The Select
query option allows the clients to requests a limited set of properties for each entity.
OrderBy¶
The OrderBy
query option allows clients to request resources in either ascending order or descending order using desc.
Filter¶
The Filter
query option allows clients to filter a collection of resources that are addressed by a request URL. The expression specified for the filter is evaluated for each resource in the collection, and only items where the expression evaluates to true are included in the response.
Filter With Json Expressions are evaluated with AND between different attributes and OR within an attribute. Default operator is equal.
A Json Filter in it's simplest form: Returns items for expression Contract=A
{
"Contract": "A"
}
A Json Filter with Multiple attributes: Returns items for expression ((OrderNo=1 OR OrderNo=2) AND (Contract=A OR Contract=B OR Contract=C))
{
"OrderNo": "1;2",
"Contract": "A;B;C"
}
You can use variables like "OderNo" : "{$input.OrderNo}"
inside the Json for the Filter query option. However note that only $
and #
works for automatic quotation of string values. Using %
does not work due to defect TAR-252.
Filter Operators¶
Default operator is equal if no operator is specified.
Supported operators:
>=
Greater Than Or Equal>
Greater Than<=
Less Than Or Equal<
Less Than!=
Not Equal=
Equal
A Json Filter with operator: Returns items for expression OrderNo>=5
{
"OrderNo": ">=5"
}
Filter Data Types¶
String
{
"Attribute1": "5",
"Attribute2": "5;7;10"
}
Number
{
"Quantity1": 5,
"Quantity2": {"Number": "5;7;10"}
}
Enumeration
{
"Enumeration1": {"Enumeration": {"Enum.SomeEnum": "Value1;Value2"}}
}
Date : Can either be a single day or a range.
{
"Date1": {"Date": "2020-12-01"},
"Date2": {"Date": "2020-12-01;2020-12-23"}
}
json linenums="1"
{
"DateTime1": {"DateTime": "2020-12-01"},
"DateTime2": {"DateTime": "2020-12-01;2020-12-23"}
}
Filter Examples¶
Example 1 :
Query ShopOrdersHandling.svc/ShopOrds Select "OrderNo,Contract" OrderBy "Contract,OrderNo desc" Filter With Json Into queryResult
{
"Contract": "MF-S1",
"OrderNo": ">=204129",
"EffPhaseInDate": {"Date": "2021-01-07;2021-01-08"}
}
Patch¶
Change an entity URL (HTTP PATCH). Requires an object retrieved either by a Get
or Create
command.
Patch
can be done conditionally by using then When
keyword.
(Also see the Modify which is an alias for Patch
)
Syntax¶
Patch {ExpectFail} [URL path to service] Using [variable] Include [HeaderKey] Into [resultVariable] When [condition]
JSON Object Body
Example : (assuming result retrieved earlier, see Get
or Create
)
Patch DockCodesHandling.svc/PurchaseDockCodes(Contract='1',DockCode='DockA') Using getResult1 Into patchResult1 When 1==