Macros - Automated Tasks
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.
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.
There are four types of Macro available from the list.
Writing a Macro
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;
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.
The result of the macro running on the selected order will be displayed in the screen below.
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"