Reputation: 251
I m trying to create an inventory transfer from a suitelet and on setting line fields, system is giving me the error to set at least one item. ERROR:
"code\":\"USER_ERROR\",\"details\":\"You must enter at least one line item for this transaction"
my code is as follows:
datamap object for lines reflecting as follows:
[{"item":"12482","fromLocation":"17","qtytoadj":"1","amount":null,"remarks":null,"project":"6621","projectTask":null,"matReqId":"8636","itemtype":"InvtPart","islotitem":"F"}]
//creating inventory transfer record
var createInvTrans = nlapiCreateRecord('inventorytransfer');
//Body fields
createInvTrans.setFieldValue('subsidiary', subsidVal);
createInvTrans.setFieldValue('location', 17);
createInvTrans.setFieldValue('transferlocation', 10);
createInvTrans.setFieldValue('custbody21', projectFld);
var toData = dataMap[matRecs];
nlapiLogExecution('debug', 'toData', JSON.stringify(toData))
nlapiLogExecution('debug', 'toData.length', toData.length)
for (var i2 = 0; i2 < toData.length; i2++) {
createInvTrans.selectNewLineItem('inventory');
createInvTrans.setCurrentLineItemValue('inventory', 'item', toData[i2].item);
createInvTrans.setCurrentLineItemValue('inventory', 'adjustqtyby', toData[i2].qtytoadj);
createInvTrans.commitLineItem('inventory');
}
//sumbitting inv Adj
var invTrans = nlapiSubmitRecord(createInvTrans, true, true);
Can anyone help me is there anything that i m doing wrong? because my Data in datamap is right as required but wherever execution reaches to set lines, the error comes.
Upvotes: 0
Views: 507
Reputation: 15462
You're using the wrong mode. You're using the dynamic mode sublist operations with a non-dynamic record.
You could do initialize the transfer as dynamic :
var createInvTrans = nlapiCreateRecord('inventorytransfer', {recordmode: 'dynamic'});
or use the server side api for the sublist:
for (var i2 = 0; i2 < toData.length; i2++) {
createInvTrans.setLineItemValue('inventory', 'item', i2 +1, toData[i2].item);
createInvTrans.setLineItemValue('inventory', 'adjustqtyby', i2+1, toData[i2].qtytoadj);
}
Upvotes: 1