How do I cancel a NetSuite import if there are no line items to import?

I have built a custom flow that gets a snapshot of inventory quantities from our 3PL via REST API and then creates inventory adjustments on the NetSuite end. This is meant to true up inventory quantities in NetSuite, but, if other inventory flows such as Item Receipts / Item Fulfillments / Inventory Transfers are working, there is a REALLY good change that there won't be ANY differences between 3PL inventory snapshot and NetSuite inventory snapshot (in which case I've used a pre map hook on the import to weed out any line items where there is no difference).

However, the import goes ahead and attempt to create an inventory adjustment without line items. Is there a way to prevent this from happening? I have written a post submit hook that "ignores" the error, but all that seems to do is to auto-resolve the error while still showing the red error light for that flow step.

I'd like to just completely cancel the import step if there are no line items to submit. How do I do this?

0

Comments

6 comments
Date Votes
  • Can you filter on your items array in the JSON object from the 3PL and make sure it's Not Empty in a Input filter to the NetSuite import??

    0
  • The inbound JSON will never be empty. There will always be hundreds / thousands of line items with quantities on hand for goods at the 3PL. However, prior to import to NetSuite, I perform a lookup to NetSuite to check on quantities on hand. I then compare to the quantities in the inbound JSON in the import's pre map hook and throw out any line items where the quantity difference is 0. So I need to be able cancel the import if there are no line items left once that comparison is made.

    But you did give me an idea. I can try to do the comparison in a postResponseMap hook right after the lookup, keep a running tab of the net quantity difference for the entire inventory adjustment. If it's 0, then I can use the input filter you are talking about! I think that should work!

    0
  • Unfortunately, custom settings are read-only. Does anyone know if there is a way to set up a global variable scoped to the flow or its execution that I can access through hooks? That might give me what I need. I tried to access with a postResponseMap hook post lookup my line item data as part of an array within the record object but that's not how the postResponseMapData appear to be formatted. This is what I got instead:

    {
      "postResponseMapData": [
        {
          "_PARENT": {},
          "ProductCode": "6516388DD-NOV-18DD",
          "LocationType": "Available Stock",
          "Quantity": 9,
          "NSQtyOnHand": "8"
        }
      ],
      "_exportId": "630f877d78aab87cba1b1323",
      "_connectionId": "62abe22e2fd46c408f127591",
      "_flowId": "630f85803f8b5a4960280bdc",
      "_integrationId": "6307b3cb27887910c1d0f026",
      "settings": {
        "integration": {
          "style": "6516602",
          "testMode": false
        },
        "flowGrouping": {},
        "flow": {},
        "export": {},
        "connection": {}
      }
    }

    I was hoping to get it in this format.

    {
      "data": [
        {
          "StockQuantityLineItem": [
            {
              "ProductCode": "6516602-BLK-08",
              "LocationType": "Available Stock",
              "Quantity": 106
            },
            {
              "ProductCode": "6516602-BLK-10",
              "LocationType": "Available Stock",
              "Quantity": 150
            },
            {
              "ProductCode": "6516602-BLK-12",
              "LocationType": "Available Stock",
              "Quantity": 237
            },
            {
              "ProductCode": "6516602-BLK-14",
              "LocationType": "Available Stock",
              "Quantity": 319
            },
            {
              "ProductCode": "6516602-BLK-16",
              "LocationType": "Available Stock",
              "Quantity": 208
            },
            {
              "ProductCode": "6516602-BLK-18",
              "LocationType": "Available Stock",
              "Quantity": 74
            },
            {
              "ProductCode": "6516602-MDN-08",
              "LocationType": "Available Stock",
              "Quantity": 10
            },
            {
              "ProductCode": "6516602-MDN-10",
              "LocationType": "Available Stock",
              "Quantity": 23
            },
            {
              "ProductCode": "6516602-MDN-12",
              "LocationType": "Available Stock",
              "Quantity": 32
            },
            {
              "ProductCode": "6516602-MDN-14",
              "LocationType": "Available Stock",
              "Quantity": 34
            },
            {
              "ProductCode": "6516602-MDN-16",
              "LocationType": "Available Stock",
              "Quantity": 34
            },
            {
              "ProductCode": "6516602-MDN-18",
              "LocationType": "Available Stock",
              "Quantity": 12
            }
          ]
        }
      ],
      "errors": [],
      "abort": false,
      "newErrorsAndRetryData": []
    }

    If I could get it in this format, I could weed out the line items with 0 difference in 3PL quantity and NetSuite quantity and use the input filter suggested above. Unfortunately, I can only get my data in this format in the preSave hook for the export and the preMap hook for the import.

    Any words of wisdom?

    0
  • You should be able to format the records however you like using the postResponseMap hook (just like with the preSavePage hook), and instead of trying to write to a custom setting (which are read only in the context of a hook execution), you can always add new fields to the records in the postResponseMapData array.  i.e. You can add a boolean field called something like 'hasInventoryChanges = true/false'.

    Taking a step back, you can also ignore records in the preMap and postMap hooks.  If you read the function stub docs very carefully, it says the following.  Hope this helps!

    * Returning an empty object {} for a specific record will indicate that the record should be ignored.

    0
  • Thank you, Scott. There are a couple of really good options you've provided. I'll create a variable local to the hook called hasInventoryChanges and then return an empty object if false. Awesome suggestions!

    0
  • Returning an empty object {} for a specific record will indicate that the record should be ignored.

    I like this option because it leverages the native behavior of IIO

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post