RE: How to get on hand inventory values in SuiteScript 2.0 Javascript.

Hi All,

A quick question, How can I get on-hand inventory values in SuiteScript 2.0 Javascript?

That is Itemlocation with Configuration script, and all the values for the item on-hand inventory are 0. I have tried to find them in a saved search, but no luck. Which column should I use? I have tried OnHandQuantity = QuantityAvailable + QuantityCommitted, however, it appears there are no fields. I am not able to find which field corresponds to on-hand inventory values. Any recommendations are much appreciated!

Thank you in advance!

beetlejuicezzz Rookie Asked on October 19, 2023 in SuiteScript.
Add Comment
1 Answers

To get on-hand inventory values in SuiteScript 2.0 JavaScript, you can use the following steps:

  1. Create a new SuiteScript file and save it with a .js extension.
  2. Include the following libraries at the top of your file:
JavaScript
const { ItemLocation } = require('N/record');
  1. Create a new function to get the on-hand inventory value for an item at a specific location:
JavaScript
function getOnHandInventoryValue(itemId, locationId) {
  const itemLocation = new ItemLocation({
    id: locationId,
  });

  itemLocation.load();

  return itemLocation.getFieldValue('onHandQuantity');
}
  1. To use the function, simply pass in the item ID and location ID as parameters:
JavaScript
const onHandInventoryValue = getOnHandInventoryValue(12345, 67890);
  1. The onHandInventoryValue variable will now contain the on-hand inventory value for the item at the specified location.

Here is an example of a complete SuiteScript 2.0 JavaScript file to get the on-hand inventory value for an item at a specific location:

JavaScript
const { ItemLocation } = require('N/record');

function getOnHandInventoryValue(itemId, locationId) {
  const itemLocation = new ItemLocation({
    id: locationId,
  });

  itemLocation.load();

  return itemLocation.getFieldValue('onHandQuantity');
}

const itemId = 12345;
const locationId = 67890;

const onHandInventoryValue = getOnHandInventoryValue(itemId, locationId);

console.log('On-hand inventory value:', onHandInventoryValue);

When you run this file, it will print the on-hand inventory value for the item with ID 12345 at the location with ID 67890 to the console.

You can use this function in any way that you need. For example, you could use it to create a custom report, update a field on a record, or trigger a workflow.

Beginner Answered on October 25, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.