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!
To get on-hand inventory values in SuiteScript 2.0 JavaScript, you can use the following steps:
- Create a new SuiteScript file and save it with a .js extension.
- Include the following libraries at the top of your file:
const { ItemLocation } = require('N/record');
- Create a new function to get the on-hand inventory value for an item at a specific location:
function getOnHandInventoryValue(itemId, locationId) {
const itemLocation = new ItemLocation({
id: locationId,
});
itemLocation.load();
return itemLocation.getFieldValue('onHandQuantity');
}
- To use the function, simply pass in the item ID and location ID as parameters:
const onHandInventoryValue = getOnHandInventoryValue(12345, 67890);
- 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:
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.