Scripting Basics

ShipStream utilizes an embedded JavaScript interpreter in many places to allow the user to define advanced business logic and customizations. The interpreter is an implementation of the 6th edition of ECMAScript known commonly as ES6 or ES2015.

See the more detailed guides for additional information about writing specific types of scripts:

How to Create a Script

  1. Navigate to System > Scripts.
  2. Click Create New Script at the top right.
  3. Select the Merchant to which the script will be applicable or "--All Merchants--" to have the script apply to all merchants.
  4. Enter a brief description for the script so you can easily identify it. This description will also appear in the order's History tab if the script has an error or prints any output.
  5. Select the script Type.
  6. Change the Is Active field to Yes if you wish to use the script after it is saved, or leave it as No to disable it for now.
  7. Set a Sort Order if using multiple scripts to control the order in which the scripts are applied. Lower numbers will run before a script with a higher number.
  8. Click Save.
If the script is Active:
Before Create Order scripts will immediately take effect on incoming orders. Existing orders, even in New status, will not be affected by Before Create Order scripts.

Javascript Editor

On pages where a user may define a script the script is submitted in a text field that has some basic syntax highlighting and validation features.

Syntax Errors

If the script contains syntactical errors code then an indicator will appear on the line number where the error is detected. Hover your cursor over the icon to see more information. All errors and warnings must be addressed before the script can be saved.

Logical Errors

The built-in editor can detect many potential problems which are not syntactical. It is recommended not to ignore these warnings as they very likely are an indicator that the script will throw a logical error or not behave as expected.

Debugging

All scripts support a print() function. This can take any arguments of any type and will cause the interpreter to "output" some information. This information will typically be captured by ShipStream and reported in an order's history or some other location relevant to the scope of the script. In general, use the print statement to provide the end users with useful information about what affect your script had or to debug your scripts.

if (order.address.country != 'MX') {
order.options.shipping_method = 'fedex_INTERNATIONAL_ECONOMY'
print('Forced order to Mexico to be shipped via FedEx International Economy')
}

How did we do?

Before Create Order Scripts

Contact