Skip to main content

Using Variables with MOCA Commands

Cycle variables can be used in conjunction with MOCA commands. Using Cycle variables allows you to build dynamic MOCA commands and to pass data into the commands. After a MOCA command is executed, the following Step allows you to save a value from the MOCA result set for later use:

I assign row <Row_Number> column <Column_Name> to variable <Variable_Name>

The figure below prompts the user for a location. Then the value entered is used as an argument to list the inventory in the location. The first load returned is stored and then echoed in the Output pane.

Using variables with MOCA commands

MOCA environment variables

Cycle includes a Step that will set MOCA environment variables for a specific test. Examples include DEVCOD, WH_ID, and LOCALE_ID.

I assign "USER_PC" to MOCA environment variable "DEVCOD"

Scripting with Environment Variables in MOCA 2020.1

Additional security in MOCA version 2020.1 has changed the parameters through which variables can be passed into MOCA environment variables.

Rather than the @@ for the environment variables used in previous inline and MOCA scripts, instead use the $ prefix on values that you want to have replaced with Cycle variables.

So if the script is:

publish data where wh_id = $wh_id and stoloc = $stoloc and prtnum = $prtnum | list inventory where @+wh_id and @+stoloc and @+prtnum

Cycle will replace the $<cycle variable> with @uc_cyc_<cycle variable> (the uc_cyc_ prefix is added to keep Cycle's variables clearly labelled in your WMS).

If the variable does not exist in the variable store, Cycle will pass in a null value and MOCA can then evaluate @uc_cyc_<non-existent variable> as null.

In addition, a Base64 encoding is used for security. So, with the above example, if there is a Cycle variable defined for wh_id with a value of WMD1 and stoloc defined with a value of SDOCK01, but no variable for prtnum, before sending it to the MOCA server, Cycle will turn the script into:

[[
def charSet = java.nio.charset.StandardCharsets.UTF_8.toString()
def decoder = java.util.Base64.getDecoder()
uc_cyc_wh_id = new String(decoder.decode("V01EMQ=="), charSet)
uc_cyc_stoloc = new String(decoder.decode("U0RPQ0swMQ=="), charSet)
uc_cyc_prtnum = null
]]
|
{
publish data where wh_id = @uc_cyc_wh_id and stoloc = @uc_cyc_stoloc and prtnum = @uc_cyc_prtnum
|
list inventory where @+wh_id and @+stoloc and @+prtnum
}

So within the MOCA environment, @uc_cyc_wh_id would be "WMD1", @uc_cyc_stoloc would be "SDOCK01", and @uc_cyc_prtnum would be null.