I have been trying to script the creation of a bin put away worksheet, to take 13000+ lines of On hand stock that does not sit in a bin, and to move that stock into bins.
The code below has some success in creating a worksheet. However, it is limited. It only works for one location. If you force it to run for another location statically, it will create the worksheet but the stock values will be taken from a different location.
I'm hoping someone can look at this code and point to the fault. Alternatively, I'm hoping someone else has already attempted to do similar and has a workable fix.
function suitelet(request, response){ if (request.getMethod() == 'GET') { // Loop through locations var filters = new Array(); filters[0] = new nlobjSearchFilter('isinactive', null, 'is', 'F'); var columns = new Array(); columns[0] = new nlobjSearchColumn('internalid'); columns[1] = new nlobjSearchColumn('name'); var locations = nlapiSearchRecord('location',null,filters,columns); var location = 0; for (var i = 0; locations != null && i < locations.length; i++) { location = locations[i].getValue(columns[0]); var binsheet = nlapiCreateRecord('binworksheet', {recordmode : 'dynamic'}); var today = new Date(); nlapiLogExecution('DEBUG', 'Value Check = ' + binsheet.getFieldValue('memo')); binsheet.setFieldValue('location', location); binsheet.setFieldValue('transdate', today.getDate()); binsheet.setFieldValue('memo', 'Auto Update'); if (binsheet.getLineItemCount('item') != 0) { for (var j = 1; j <= binsheet.getLineItemCount('item'); j++) { binsheet.selectLineItem('item', j); var item = binsheet.getLineItemValue('item', 'item', j); var qty = binsheet.getLineItemValue('item', 'quantity', j); var itemrecord = nlapiLoadRecord('inventoryitem', item); var linecount_bin = itemrecord.getLineItemCount('binnumber'); var bin = 0; if (linecount_bin != 0) { for (var rep = 1; rep <= linecount_bin; rep++) { if (itemrecord.getLineItemValue('binnumber', 'location', rep) == location) { bin = itemrecord.getLineItemValue('binnumber', 'binnumber', rep); } } } if (bin != 0) { var subRecord = binsheet.createCurrentLineItemSubrecord('item', 'inventorydetail'); subRecord.selectNewLineItem('inventoryassignment'); subRecord.setCurrentLineItemValue('inventoryassignment', 'quantity', qty); subRecord.setCurrentLineItemValue('inventoryassignment', 'binnumber', bin); subRecord.commitLineItem('inventoryassignment'); subRecord.commit(); } binsheet.commitLineItem('item'); } nlapiSubmitRecord(binsheet); } } } }