I am trying to automate doing an Adjust worksheet using a restlet in netsuite with the code below:
/**
* @NApiVersion 2.0
* @NScriptType Restlet
* @NModuleScope SameAccount
*/
define([
'N/record','N/format',
], function(record,format) {
function postInv(data){
var recordObj = record.create({
type: "inventoryworksheet",
isDynamic: true
});
var location = data.location;
var account = data.account;
var region = data.region;
var countedby = data.countedby;
var datee = format.parse({value: data.date, type: format.Type.DATE});
var memo = data.memo;
var trans_order = data.trans_order;
var inv_type = data.inv_type;
var item_group = data.group;
recordObj.setValue({
fieldId:'trandate',
value:datee
});
recordObj.setValue({
fieldId:'location',
value:location
});
recordObj.setValue({
fieldId:'account',
value:account
});
recordObj.setValue({
fieldId:'department',
value:region
});
recordObj.setValue({
fieldId:'lastinday',
value:trans_order
});
recordObj.setValue({
fieldId:'custbody44',
value:inv_type
});
recordObj.setValue({
fieldId:'memo',
value:memo
});
recordObj.setValue({
fieldId:'custbody43',
value:countedby
});
recordObj.setValue({
fieldId:'Item_PARENT',
value:item_group
});
var items = data.items;
var recordsublist = recordObj.getSublist({sublistId: "invt"});
var linecount = recordObj.getLineCount({sublistId: 'invt'});
for (i = 0; i < items.length; i++) {
//Search for items line number
var lineNumber = recordObj.findSublistLineWithValue({
sublistId: 'invt',
fieldId: 'invtid',
value: items[i][0]
});
recordObj.selectLine({
sublistId: 'invt',
line: lineNumber
});
recordObj.setCurrentSublistValue({
sublistId: 'invt',
fieldId: 'invtnewqty',
value: items[i][1]
});
recordObj.commitLine({
sublistId:'invt'
});
}
var recordId = recordObj.save({
enableSourcing: false,
ignoreMandatoryFields: false
});
var r = record.load({
type: 'inventorytransfer',
id: recordId,
isDynamic: true,
});
return r;
}
return {post:postInv};
});
Since Netsuite hasnt implemented a proper way to Adjust worksheet programmatically, I figured its possible to load the whole Adjust worksheet then loop through all the records and only set the values I want, just like I would in the UI. However this is a bit slow since 10,000 records are loaded by default. I have over 16k items so this also means some wont show in the loaded records.
To make this simpler I tried to only load a single group by specifying the sub-item field using
recordObj.setValue({
fieldId:'Item_PARENT',
value:item_group
});
However it seems this is just ignored and the whole 10,000 records is still loaded but I think its because the record doesn't change dynamically like in the UI once its been loaded.
Is there a way I can specify the group to load right at the start?