Macros - Automated Tasks

Videos and Files


Overview

Macros is a small piece of programming code which is triggered when an even happens in the system. This allows you to program some workflow functionality into Linnworks using its own evaluation parser. This document describes how to set up and use macro. We will not discuss in details the macro syntax as this is beyond the scope of this manual, but rather present couple of examples on how to achieve some degree of custom workflow (automation) within the system without invoking any bespoke changes.

Custom variables can also be created within the macro it's self.

The Macros feature can be found in the Settings tab.

The macro screen is split into two parts. The macro list and the script editor.

The macro list enables you to see the macros you have created, the type of macro, in which order it gets executed and if it is enabled or not.

Creating a New Macro

To create a new macro click the Add New button.

The add new button enables the user to add a new macro to the screen

This will display the New Macro Screen. Next select the type of macro you wish to select and give the macro a name, click ok to add the macro.

Enables the user to select the type of macro and the name of the macro.

There are four types of Macro available from the list.

OUTPUT create a system value and records it in the system config table
NEW_ORDER executed whenever new order is added in the system by means of raising new order or downloading new order from integrated source (eBay/Amazon/Website/Playtrade/Pixmania/Other)
EDIT_ORDER triggered whenever an order is edited
PROCESSED_ORDER triggered whenever the order is processed

Writing a Macro

Variables

Since orders are based on variable information these are used to evaluate data where the information type is known, or in other words "Variables are symbolic names given to a an unknown piece of information".  An example of an order variable would be OrderPostage.PostalServiceName. This variable is split into two sections. The first is the category of information being searched, in this case the category is Order Postage. The next is the name of the field within the category, Postal Service Name. 

Using your own variables

Within the Macro Screen it's possible to create your own variables. The means that formulae can be applied to a variable and then validated again from there.

a := 1;
b := 2;

Order.fPostageCost := a + b;

The out come of the above would the addition of a and b, then applying the result it to the postage cost

postage: = Order.fPostageCost;
oldvat: = 1.175;
newvat: = 1.2;

Order.fPostageCost :=  (postage / oldvat)*newvat;

Operators

AND

The AND operator can be used when using multiple variables within a condition. When using the AND operator all conditions have to be true for the conditon to be true.

OrderPostage.TotalWeight>5000 AND Order.Source="AMAZON"
It is not possible to use an AND for multiples of the same variable, i.e. an order cannot have Order.Source as AMAZON and EBAY.

OR

The OR operator can be used when using multiple variables within a condition. When using the OR operator only one of the conditions has to be true for the output to display.

Order.Source="EBAY" OR Order.Source="AMAZON"

=

The equals sign is used to evaluate the variable against the given text. The text provided must match the variable exactly for the condition to be true

<>

This operator means NOT EQUAL or in other words does not equal.

Order.fPostageCost<>0

The above condition will be true when the Postage Cost is not 0

>

This operator means GREATER THAN. This can be used when evaluating numerical values.

Order.fPostageCost>4.95

This will mean that anything with the postage cost above 4.95 will be true. If the postage cost is 4.95 then the condition is false as it is greater than, not greater than or equal to.

<

This operator means LESS THAN. This can be used when evaluating numerical values.

Order.fPostageCost<4.95
This will mean that anything with the postage cost below 4.95 will be true. If the postage cost is 4.95 then the condition is false as it is less than, not less than or equal to.

>=

This operator means GREATER THAN or EQUAL TO. This can be used when evaluating numerical values.

Order.fPostageCost>=4.95
This will mean that anything with postage cost above or equal to 4.95 will be true.

<=

This operator means LESS THAN or EQUAL TO. This can be used when evaluating numerical values.

Order.fPostageCost<=4.95

This will mean that anything with postage cost below or equal to 4.95 will be true.

Formulae

IIF Statement

An IIF or IF statement is a conditional statement that revolves around a statement being true or false. If the condition in the statement is true then it will return the first, else it will return the second value.

Example - Allocating postage based on weight

OrderPostage.PostalServiceName := iif[OrderPostage.TotalWeight>5000,"DHL Next Day", OrderPostage.PostalServiceName];

The example is Allocating the Postal Service Name of order with weight over 5000g to DHL Next Day. If the order is not over 5000g the macro will assign OrderPostage.PostalServiceName to the macro, or in other words it will keep the service it's currently on.

Example - Using multiple conditions

OrderPostage.PostalServiceName := iif[OrderPostage.TotalWeight>5000 AND Order.cCountry="United Kingdom","DHL Next Day", OrderPostage.PostalServiceName];

The above will assign DHL Next Day to any order with weight over 5000g AND the order country is United Kingdom

Example - Using multiple conditions and parentheses

OrderPostage.PostalServiceName := iif[(OrderPostage.TotalWeight>5000 AND Order.cCountry="United Kingdom") OR Order.cCountry="Germany","DHL Next Day", OrderPostage.PostalServiceName];

The advantage of using parentheses is each sets/groups of conditions will be evaluated separately and then joined by the operators between the sets.

Running the Macro

Once you have written the macro you can test it be clicking RUN.

When you click run on a NEW_ORDER macro it will prompt you to enter an order number to test it on. Enter the order number and click ok.

Macro_Programming_Run_Macro_Order_Number.png

The result of the macro running on the selected order will be displayed in the screen below.

Macro_Programming_Macro_Result.png

The Was section is the origional data for the order.

The Become section is the changes made to an order. If a change was made the result will be highlighted in dark blue. For the above the Postal Service was changed from "MP - Royal Mail Recorded and Special - Recorded" to "DHL Next Day"