# NetSuite > Shopify - inventory/stock

## Introduction

A SuiteQL query looks for inventory level changes in NetSuite, and retrieves items that have had quantity updates within a given lookback period. This data is batched, mapped, and cached for later use.&#x20;

{% hint style="info" %}
The lookback date is calculated by referencing `datefrom` and `dateto` [flow variables](#flow-variables) in `TO_IMESTAMP` functions at the end of the query. &#x20;
{% endhint %}

Next, a script extracts all unique SKUs from this data and builds a query string that can be used to look up these products in Shopify. The data is then filtered and appended to the existing cache.

Having retrieved inventory data from Shopify, cached data is loaded back into the flow. A script then runs, comparing NetSuite inventory items against Shopify’s inventory data, to determine any quantities that need updating (i.e. Delta values).&#x20;

{% hint style="info" %}
This flow is designed to handle multiple locations - additional branches can be added if required.&#x20;
{% endhint %}

## Process flow snapshot

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FSUvxsp8XwrC9qsafJMIe%2Ficon%20process%20flow.svg?alt=media&#x26;token=ad1dc886-4a4e-4cad-9ad0-3d755e0f3b5a" alt="" data-size="line"> Click to view process flow snapshot</summary>

<img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FtSbd4N3v57heVrI8hC20%2FNetSuite%20%3E%20Shopify%20-%20inventory%3Astock%20full%20flow%20b.png?alt=media&#x26;token=091259e1-2e8e-4787-a35a-f18031f074f5" alt="" data-size="original">

</details>

## Limitations

<table><thead><tr><th width="266.79296875">Limitation</th><th>Summary</th></tr></thead><tbody><tr><td>Shopify GraphQL error handling</td><td>There is a known limitation with error handling for Shopify GraphQL. Please refer to the <a href="../../installation-guide-shopify-and-netsuite/stage-5-review-update-and-test-process-flows-shopify-and-netsuite#error-handling-for-shopify-graphql">Error handling for Shopify GraphQL</a> section for more information and a suggested approach that you may wish to adopt in your flows. </td></tr></tbody></table>

## Assumptions

There are no assumptions to note for this flow.

## Customisation

To ensure that this process flow runs as required, some customisation options are available. These are documented in the following sections:

* [Flow variables](#flow-variables)
* [Process shape shapes](#process-flow-shapes)
* [Branching for multiple locations](#branching-for-multiple-locations)

### Flow variables

The table below summarises [flow variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables) defined for this process flow.

<table><thead><tr><th width="163.5078125">Flow variable</th><th>Summary</th><th>Default value</th></tr></thead><tbody><tr><td><code>datenow</code></td><td>Set the relative time period to start looking for updated inventory items in NetSuite. Update the default value as required.</td><td>+0 minutes</td></tr><tr><td><code>datefrom</code></td><td>Set the relative time period to look back for updated inventory items in NetSuite. Update the default value as required.</td><td>-10 minutes</td></tr></tbody></table>

{% hint style="info" %}
For information on working with flow variables, please refer to our [flow variables documentation](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables).
{% endhint %}

### Process flow shapes

This process flow includes some shapes that can be configured with your own settings. Please see guidelines in the table below.

{% hint style="warning" %}
Shape settings determine the outcome of process flows. Do not change shape settings unless they are listed below.&#x20;
{% endhint %}

<table data-full-width="false"><thead><tr><th width="165.34375">Shape</th><th>Notes</th></tr></thead><tbody><tr><td>Trigger</td><td><p>The default setting is to run every 10 minutes (recommended) but you can change the schedule if required.</p><p></p><p>Keep in mind that the NetSuite connector includes a query that retrieves items updated within a given lookback period (based on <a href="#flow-variables">flow variables</a>). You should ensure that the trigger schedule aligns with your lookback period.</p></td></tr><tr><td>Notify</td><td>This flow is designed in a try/catch structure, so notifications are generated if any part of the flow fails. To achieve this, the <code>catch</code> route includes a <a href="../../../../process-flows/building-process-flows/process-flow-shapes/standard-shapes/notify-shape">notify shape</a>, which must be configured for your own notification preferences. <br><br><code>Alert level</code>: Defaults to <code>error</code> but can be changed if needed<br><code>Channel</code>: Defaults to <code>email + log</code> but can be changed if needed<br><code>Email Limit</code>: Defaults to <code>5</code> but can be changed if needed<br><code>Notification Group</code>: Replace the <code>notify</code> placeholder which your required notification group. <br><code>Message</code>: If required, you can change the placeholder message.<br><br>For more information, please refer to our <a href="../../../../process-flows/building-process-flows/process-flow-shapes/standard-shapes/notify-shape">Notify shape</a> and <a href="../../../../general-settings/notification-groups">Notification groups</a> pages.</td></tr><tr><td>Connector (NetSuite)</td><td>If you did not add or select a NetSuite instance during the blueprint <a href="../installation-guide-shopify-and-netsuite/stage-4-install-the-blueprint-shopify-and-netsuite">installation process</a>, the following settings must be configured:<br><br><code>Source instance</code> : Set to your required <code>NetSuite</code> instance.<br><code>Source endpoint</code> :  Set to <code>POST suiteQL</code><br><code>Query</code> : Leave as it defaults. This variable references your <code>datenow</code> and <code>datefrom</code> flow variables to determine the lookback period for updated items. Make sure these <a href="#flow-variables">flow variables </a>are set as required.</td></tr><tr><td>Connector (Shopify)</td><td>If you did not add or select a Shopify instance during the blueprint <a href="../installation-guide-shopify-and-netsuite/stage-4-install-the-blueprint-shopify-and-netsuite">installation process</a>, the following settings must be configured:<br><br><code>Source instance</code> : Set to your required <code>Shopify</code> instance.<br><code>Source endpoint</code> :  Set to <code>POST Retrieve inventory data by graphql</code></td></tr><tr><td>Split</td><td>The <code>level to split</code> value must be updated with the name of your NetSuite warehouse location (exactly as it appears in NetSuite).</td></tr><tr><td>Connector (Shopify)</td><td><p>If you did not add or select a Shopify instance during the blueprint <a href="../installation-guide-shopify-and-netsuite/stage-4-install-the-blueprint-shopify-and-netsuite">installation process</a>, the following settings must be configured:</p><p></p><p><code>Source instance</code>: Set to your required <code>Shopify</code> instance.</p><p><code>Source endpoint</code> :  Set to <code>POST Inventory adjust quantities graphql</code>     </p><p><code>Variables</code>: Leave <code>Inventory ID</code> , <code>Delta</code>, and <code>Location ID</code> as defaults.</p></td></tr><tr><td>Error handling route</td><td>This flow includes a <code>route</code> shape named <code>error handling</code>, with routes designed to provide additional error handling. You can update the notify shape as required. <br><br>Note that this route shape relates to the <a href="#limitations">Shopify GraphQL limitation</a> noted above. This same route shape can be applied wherever you feel appropriate in process flows. </td></tr></tbody></table>

### Branching for multiple locations

If you need to update this flow to handle multiple locations, you can do so as follows:

{% stepper %}
{% step %}
**Add a branch shape**&#x20;

Add a [branch shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/branch-shape) immediately after the second script shape - for example:

<img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fgk5Fj46BAoM6cxi0AE0M%2Fbranch%20example.png?alt=media&#x26;token=9af78a6d-8425-4ee0-916a-baeabdd3ed8f" alt="" data-size="original">

All subsequent shapes are moved to the first branch and a second branch is added. If required, add more branches.
{% endstep %}

{% step %}
**Replicate first branch shapes in new branches**

Add all shapes found in the first branch to each new branch, with the same configuration. &#x20;
{% endstep %}

{% step %}
**Update split shapes**

On every branch (including the first one), edit the split shape. Here, change the `level to split` field to the name of a warehouse location (exactly as it appears in NetSuite). For example:

![](https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F5CUPiiCZz65PBDvQsgik%2Fsplit%20shape%20settings.png?alt=media\&token=c3f284f3-3501-4547-9866-71b9a8885aff)

This location name is passed into the subsequent script, so the remaining flow processes for this location
{% endstep %}
{% endstepper %}

## Reference

Reference information for this process flow is documented in the following sections:

* [Scripts used in this process flow](#scripts-in-this-process-flow)
* [Cross-reference lookups used in this process flow](#cross-reference-lookups-in-this-process-flow)

### Scripts in this process flow

<table><thead><tr><th width="293">Script</th><th>Summary</th></tr></thead><tbody><tr><td>Inventory - generate shopify graphql</td><td>Query string to search SKUs in Shopify.</td></tr><tr><td>Calculate inventory adjustments for multiple locations</td><td>Calculate inventory adjustments for multiple locations - checks the inventory between both systems to create a delta value for shopify.</td></tr></tbody></table>

### Cross-reference lookups in this process flow

This process flow does not use cross-reference lookups.
