We have a “kitting” strategy in place in our item ...
# suiteql
w
We have a “kitting” strategy in place in our item hierarchy. So a “kit” can have components and those components can be other kits or actual items. I’ve come to understand that the kits with components are native to NS. I’m trying to figure out how these component lists for the kit items are related to the kit items in the DB. I’ve found this: https://timdietrich.me/blog/netsuite-suiteql-kit-package-item-components/ (thanks again @tdietrich !) We have kits with 3 levels deep nesting until you hit actual items. I’m wondering about pulling this data - I don’t think I can do it in a single query. Not sure. Any thoughts?
👍 1
Here’s my initial query:
Copy code
# First query is items
# Second query is kits with items that have inventory
<<~STOP
  SELECT    Item.id,
            Item.Itemid AS sku,
            Item.displayname AS name,
            InventoryItemLocations.quantityavailable AS available_inventory,
            Item.#{ITEM_OLD_SKU_FIELD} AS old_sku,
            Item.cost,
            Item.#{ITEM_IMAGE_FIELD} AS photo_url
  FROM      Item AS Item
  JOIN      InventoryItemLocations
    ON InventoryItemLocations.Item = Item.id
  WHERE     InventoryItemLocations.Location = '#{warehouse_id}'
  AND       Item.itemtype = 'InvtPart' AND InventoryItemLocations.quantityavailable > 0
  AND       Item.isinactive = 'F'

  UNION

  SELECT    DISTINCT ParentItem.id,
            ParentItem.Itemid AS sku,
            ParentItem.displayname AS name,
            NULL AS available_inventory,
            NULL AS old_sku,
            NULL AS cost,
            NULL AS photo_url
  FROM      Item AS ParentItem
  JOIN      KitItemMember
    ON KitItemMember.ParentItem = ParentItem.ID
 JOIN      Item AS MemberItem
    ON MemberItem.ID = KitItemMember.Item
 WHERE ParentItem.Itemid != 'AG Test Item Group'
 AND EXISTS (SELECT  *
             FROM    InventoryItemLocations
             WHERE   InventoryItemLocations.Item = MemberItem.id
             AND     InventoryItemLocations.Location = '#{warehouse_id}'
             AND     InventoryItemLocations.quantityavailable > 0)  
  ORDER BY  name
STOP
I can basically pull all kits that have inventory and then for those kits that are members of kits, I can compose the subkit results to determine if the parent kits have inventory. So not one query, but close.