6
votes

I have the multiple locations feature enabled and multi-location inventory. I need a way to set or retrieve location-specific values, such as Location On Hand, Location Next Count Date, Location Last Count Date, Location Inventory Count Interval.

These fields are accessible through the Saved Search interface, but there is no documentation on SuiteAnswers on how to get at them through SuiteScript APIs. The SuiteScript Records browser does not have entries for accessing this sublist. How can I set or retrieve values with the SuiteScript API without using searches?

Specifically, I want to be able to load a record, set the Next Inventory Count date for a specific location, and then submit and close and actually see the changes in Netsuite. Currently the only workaround I've found is awkwardly building a CSV file in suitescript and submitting that with the job manager, but that has its own limitations.

2

2 Answers

10
votes

The sublist name is undocumented and not officially supported, but you can still access it with the sublist ID "locations", IE

//load arbitrary item record
var itemRec = nlapiLoadRecord('inventoryitem', 655009)

//find the line with location internal ID 1
var line = itemRec.findLineItemValue('locations','location',1);
//get that line's location count interval
var countinterval = itemRec.getLineItemValue('locations', 'invtcountinterval', line);

//calculate the next count date as today + interval, set up the
//last count date as a string
var lastCountDate = nlapiDateToString(new Date());
var nextCountDate = new Date() + countInterval*MILLISECONDS_IN_DAY;
nextCountDate = nlapiDateToString(nextCountDate);

//set the values on the item
itemRec.setLineItemValue('locations','lastinvtcountdate', line, lastCountDate);
itemRec.setLineItemvalue('locations','nextinvtcountdate', line, nextCountDate);

nlapiSubmitRecord(itemRec);

You can discover the field names for the sublist by using something like "Inspect Element" in chrome on the sublist interface. For example, right click on the "Next Inventory Count Date" header on the locations sublist of any item, and click "Inspect Element". Looking at the div.listheader that comes up, right above that you will see something like

.elements['locationssortfld'].value='nextinvtcountdate'

The 'nextinvtcountdate' would be the field ID that you plug in to the field argument of nlapiSetLineItemValue.

Hope that helps someone. I had a hell of a time figuring this out by myself the first time around, although it seems more obvious now.

0
votes

You can also access the fields you want from a search using these field ids.

new nlobjSearchColumn("locationquantityavailable",null,null) 
new nlobjSearchColumn("locationquantityonhand",null,null) 
new nlobjSearchColumn("locationlastinvtcountdate",null,null, 
new nlobjSearchColumn("locationnextinvtcountdate",null,null) 
new nlobjSearchColumn("locationinvtcountinterval",null,null)