Get the knowledge and inspiration you need to expand your business, straight to your inbox.


How To: Filtering Data with Scripts

Scripts in Linnworks
In Linnworks scripting, the most important thing to do is make sure that the data your script is evaluating and applying changes to is the correct set of information. Continuing from our
previous article, this is intended for those with development experience wanting to write their own Linnworks scripts.

If the data is incorrect, the script will never find what it is looking for; If there's too much data, it will mean the script takes longer to run and consumes more resources, slowing down your sync.
At busy times of year this increase in running time can multiply across the greater number of incoming orders, and may force Linnworks to 'skip' a sync because the process continues when a new sync is/was due to start. This example is illustrating this by searching for all orders with the Source "AMAZON".
There are two ways to manage which data you are working with. You can use statements in the code to control which orders you will perform an action on (Order Method), or you can use an SQL Query to pre-filter the order data you pass to the script (Filter Method). Please see below for examples and information on these 2 methods, both of which are appropriate for different situations.
Order MethodEasier to use for those who aren't confident in writing SQL Queries. Harder to miss when reading through the code. This will mark the script as run on an order, regardless of whether it came from Amazon or not. Script will not run any further instructions if the condition isn't met. Click on the image to enlarge.
Filter Method
Calculations are performed on the database so it could, potentially, do more complicated things more efficiently. Linnworks won't even try to run the script on the order if the condition isn't satisfied, speeding the sync up slightly as we don't have to update any records in the database. Click on the image to enlarge.

The sample code c
an be found at this link here.

Topics: Linnworks News, Linnworks 'How To'