Expand your SuiteScript skills in the Sustainable SuiteScript community for NetSuite developers.

Location-Specific Inventory Searches with SuiteScript

Created: February 8, 2024

This is a sample chapter adapted from the "Transaction Searches with SuiteScript 2.1" Cookbook, part of the SuiteScript by Example series.

In NetSuite, we can retrieve Inventory values via Searches on the Item record, which has a number of Inventory-specific Filters and Columns.

How much On Hand Inventory do I have for each Item?

First, NetSuite Items offer a number of columns for determining the total Inventory you have for an Item across all Locations.

This code example uses the require function for importing modules. This allows you to copy and paste the snippets directly into the debugger or your browser's developer console and run them. For more on how to test SuiteScript in your browser's console, watch my tutorial video .

/**
 * Retrieves the On Hand Inventory for the 10 Inventory Items
 * with the most On Hand quantity
 *
 * @author Eric T Grubaugh <eric@stoic.software> (https://stoic.software/)
 */
require(['N/search'], (s) => {
  const printOrder = (result) => {
    const item = result.getValue({ name: 'displayname' })
    const onHand = result.getValue({ name: 'quantityonhand' })

    console.log(`${item} on hand: ${onHand}`)

    return true
  }

  s.create({
    type: s.Type.INVENTORY_ITEM,
    filters: [
      ['type', s.Operator.IS, 'InvtPart'], 'and',
      ['quantityonhand', s.Operator.ISNOTEMPTY, '']
    ],
    columns: [
      { name: 'displayname' },
      { name: 'quantityonhand', sort: s.Sort.DESC }
    ]
  }).run().getRange({ start: 0, end: 10 }).forEach(printOrder)
})

The Search Filters and Columns for total Inventory all start with quantity*, e.g. quantityonhand, quantityonorder, etc.

As always, see the Item page in the Records Browser for the complete list.

What is my Inventory breakdown at a specific Location?

Next, NetSuite Items also allow you to retrieve Inventory quantity values for a specific Location using a separate set of Filters and Columns.

/**
 * Retrieves the On Hand Inventory for the 10 Inventory Items
 * with the most On Hand quantity
 *
 * @author Eric T Grubaugh <eric@stoic.software> (https://stoic.software/)
 */
require(['N/search'], (s) => {
  const printOrder = (result) => {
    const item = result.getValue({ name: 'displayname' })
    const onHand = result.getValue({ name: 'locationquantityonhand' })
    const onOrder = result.getValue({ name: 'locationquantityonorder' })
    const backOrder = result.getValue({ name: 'locationquantitybackordered' })

    console.group(item)
    console.log(`On Hand: ${onHand}`)
    console.log(`On Order: ${onOrder}`)
    console.log(`Backordered: ${backOrder}`)
    console.groupEnd()

    return true
  }

  s.create({
    type: s.Type.INVENTORY_ITEM,
    filters: [
      ['type', s.Operator.IS, 'InvtPart'], 'and',
      ['inventorylocation', s.Operator.ANYOF, ['4']], 'and',
      ['locationquantityonhand', s.Operator.ISNOTEMPTY, '']
    ],
    columns: [
      'displayname',
      'locationquantitybackordered',
      'locationquantityonhand',
      'locationquantityonorder'
    ]
  }).run().getRange({ start: 0, end: 10 }).forEach(printOrder)
})

The Search Filters and Columns for Location-based Inventory all start with locationquantity*, e.g. locationquantityonhand, locationquantityonorder, etc. See the Records Browser for the complete list.

In order to use these locationquantity* Columns, you must specify the inventorylocation Filter in your Search.