Comment on page

Variables

Describes how Trayse Inventory uses Variables

Script Variables

Script variables are lower camel case, like field names. E.g.
$totalQty
$$totalQty
Variables for primary and foreign keys are also like the field names. E.g.
$itemID
$warehouseID
The ID is capital and at the end of the string.
Calculations are often defined inside a script variable instead of the Set Field definition. This makes it easier to see the variable before setting the field when debugging.
This
Set Variable [ $tempPendingValue ; Value: ORDERLINE::qtyPending * -1 ]
Set Field [ ORDERLINE::qtyPending ; $tempPendingValue ]
Rather than this
Set Field [ ORDERLINE::qtyPending ; ORDERLINE::qtyPending * -1 ]

Global

A handful of global variables are defined during the startup process. E.g.
$$systemPlatform
$$hostedPath
$$device
The variables defined at startup are intended to remain for the duration of the session.
Global variables defined in other scripts are created when it is easier than passing a local variable through various subscripts. These global variables are managed in such a way that they are cleared after user. This usually occurs at the end of a script:
#clean up
Set Variable [ $$warehouseID ; Value: "" ]

Passing Variables

If a single variable is passed from one script to another, then the variable is listed as a parameter.
If multiple variables are passed, then those variables are defined in the script and packaged as a JSON object within another variable called $parameter. E.g.
Set Variable [ $itemID ; Value: ITEM::ID ]
Set Variable [ $sku ; Value: ITEM::sku ]
Set Variable [ $parameters ; JSONSetElement ( "" ; [ "itemID" ; $itemID ; JSONStirng ] ;[ "sku" ; $sku ; JSONStirng ] ]
Perform Script [ Specified: From list; "script name here (itemID, sku)" ; Parameter: $parameters ]

Receiving Multiple Variables

Receiving multiple variables is done in two steps:
  1. 1.
    Get the script parameter
  2. 2.
    Unpack the JSON element
E.g.
Set Variable [ $parameters ; Value: Get ( ScriptParameter) ]
Set Variable [ $itemID ; Value: GetAsNumber (JSONGetElement ( $parameters ; "itemID" ]
Set Variable [ $sku ; Value: GetAsNumber (JSONGetElement ( $parameters ; "sku" ]
Set Variable [ $price ; Value: GetAsNumber (JSONGetElement ( $parameters ; "price" ]

Calculation Variables

Calculation variables occur in Let () statements and While () statements. These are prepended with an underscore. These variables are also indented by two spaces. E.g.
Let ([
_today = Get ( CurrentDate ) ;
_thisMonth = Month ( _today )
etc.