Hello,
I have two functions in a script, one works the other does not.
First function based on inventory balance:
function getQtyFromWestbury(itemId) {
let qty = 0;
//Search: 'Inventory Balance Search'
let inventorySearch = search.create({
type: 'inventorybalance',
filters:
[
['item','anyof',itemId],
'AND',
['location','anyof','4'] // Westbury
],
columns:
[
search.createColumn({name: 'item'}),
search.createColumn({name: 'available'}),
search.createColumn({
name: 'type',
join: 'item'
})
]
});
inventorySearch.run().each(function(result){
const qtyAvailable = parseInt(result.getValue({name: 'available'})) || 0;
const itemNameText = result.getText({name: 'item'});
const itemType = result.getValue({name: 'type', join: 'item'});
log.debug('getBalanceFromWestbury', 'The available quantity for item ' + itemNameText + ' of type ' + itemType + ' in Westbury is ' + qtyAvailable);
qty += qtyAvailable;
return true;
});
return qty;
}
This works just fine. I tried to mimic it to search Item Location Available Quantity with this function:
function getAvailFromWestbury(itemId) {
let qty = 0;
//Search: 'Item Location Available'
let itemLocSearch = search.create({
type: 'item',
filters:
[
['item','anyof',itemId],
'AND',
['inventorylocation','anyof','4']
],
columns:
[
search.createColumn({name: 'item'}),
search.createColumn({name: 'type'}),
search.createColumn({name: 'locationquantityavailable'})
]
});
itemLocSearch.run().each(function(result){
const qtyAvailable = parseInt(result.getValue({name: 'locationquantityavailable'})) || 0;
const itemNameText = result.getText({name: 'item'});
const itemType = result.getValue({name: 'type'});
log.debug('getAvailFromWestbury', 'The location avail qty for item ' + itemNameText + ' of type ' + itemType + ' in Westbury is ' + qtyAvailable);
qty += qtyAvailable;
return true;
});
return qty;
}
I have tried changing type to "assemblyitem" and tried every variation of column syntax and column field names, but I get this error every time:
{"type":"error.SuiteScriptError","name":"SSS_INVALID_SRCH_COL","message":"An nlobjSearchColumn contains an invalid column, or is not in proper syntax: item.","id":"","stack":["Error\n at getAvailFromWestbury (/SuiteScripts/acs_sl_update_item_cry.js:606:29)\n at Object.onRequest (/SuiteScripts/acs_sl_update_item_cry.js:42:35)"],"cause":{"type":"internal error","code":"SSS_INVALID_SRCH_COL","details":"An nlobjSearchColumn contains an invalid column, or is not in proper syntax: item.","userEvent":null,"stackTrace":["Error\n at getAvailFromWestbury (/SuiteScripts/acs_sl_update_item_cry.js:606:29)\n at Object.onRequest (/SuiteScripts/acs_sl_update_item_cry.js:42:35)"],"notifyOff":false},"notifyOff":false,"userFacing":true}
| Is there anything obvious I am missing here? Or can you recommend the easiest way to lookup an item's location qty available? |
| Any help is greatly appreciated! |