User event script for record load of inventory ite...
# suitescript
m
User event script for record load of inventory item, trying to get the location quantity available based on the internal Id of the location however getting error of Quantity Available: undefined... is the field Id correct for locationquantityavailable? snippet: var location = newRecord.getSublistValue({ sublistId: 'item', fieldId: 'location', line: i }); var itemTypeRecordTypeMap = { 'InvtPart': record.Type.INVENTORY_ITEM, 'NonInvtPart': record.Type.NON_INVENTORY_ITEM, 'Assembly': record.Type.ASSEMBLY_ITEM }; var itemTypeRecordType = itemTypeRecordTypeMap[itemType];
if (itemTypeRecordType) {
var itemObj = record.load({
type: itemTypeRecordType,
id: itemId,
isDynamic: true
});
var locationQuantityAvailable = itemObj.getCurrentSublistValue({
sublistId: 'locations',
fieldId: 'locationquantityavailable'
}); }
e
locationquantityavailable
is not a field on the Inventory Item record; you can determine that by noting it is not listed in the Records Browser. It is instead a Search Column in an Item search. Instead of loading the record, you'll want to perform a search via
N/search
m
ah okay thanks @erictgrubaugh.. using the search module, would it be something like: var itemRecordSearch = search.create({ type: 'item', filters: [ ['internalid', 'anyof', itemId], 'AND', ['locationquantityavailable.location', 'anyof', location], 'AND', ['formulatext: {itemtype}', 'equalto', itemType] ], columns: [ search.createColumn({ name: 'locationquantityavailable', join: 'location', summary: 'SUM' }) ] });
e
The filter you want will be
inventorylocation
. Here's a 2.0 example straight out of my old cookbook:
Copy code
require(["N/search"], function (s) {
    s.create({
        type: s.Type.INVENTORY_ITEM,
        filters: [
            ["inventorylocation", s.Operator.ANYOF, ["4"]], "and",
            ["locationquantityonhand", s.Operator.ISNOTEMPTY, ""]
        ],
        columns: [
            {name: "displayname"},
            {name: "locationquantitybackordered"},
            {name: "locationquantityonhand"},
            {name: "locationquantityonorder"}
        ]
    }).run().getRange({start: 0, end: 10}).forEach(printOrder);
    
    function printOrder(result) {
        console.group(result.getValue({name:"displayname"}));
        console.log("On Hand: " +
            result.getValue({name:"locationquantityonhand"})
        );
        console.log("On Order: " +
            result.getValue({name:"locationquantityonorder"})
        );
        console.log("Backordered: " +
            result.getValue({name:"locationquantitybackordered"})
        );
        console.groupEnd();
        return true;
    }
});
🙏 1
Note that it's only grabbing 10 results, but the concept is there to get you the location-specific inventory values