UNEXPECTED_ERROR creating vendor payment using suitescript/restlet
var vendorBillPayment = recordModule.create({ type: recordModule.Type.VENDOR_PAYMENT, isDynamic: false, defaultValues: { entity: vendorId } }); vendorBillPayment.setValue({ fieldId: 'account', value: accountId }); vendorBillPayment.setValue({ fieldId: 'currency', value: currencyId }); vendorBillPayment.setValue({ fieldId: 'exchangerate', value: exchangeRate }); vendorBillPayment.setValue({ fieldId: 'externalid', value: refNum }); vendorBillPayment.setValue({ fieldId: 'trandate', value: txnDate }); vendorBillPayment.setValue({ fieldId: 'tobeprinted', value: printStatus }); vendorBillPayment.setValue({ fieldId: 'memo', value: description }); for(var i=0; i < txnRequestMapJson.linkedTxns.length; i++){ var linkedTxn = txnRequestMapJson.linkedTxns[i]; vendorBillPayment.setSublistValue({ sublistId: 'apply', fieldId: 'apply', line: i, value: true }); vendorBillPayment.setSublistValue({ sublistId: 'apply', fieldId: 'internalid', line: i, value: linkedTxn.txnId }); vendorBillPayment.setSublistValue({ sublistId: 'apply', fieldId: 'amount', line: i, value: linkedTxn.txnAmount }); } var recordId = vendorBillPayment.save({ enableSourcing: false, ignoreMandatoryFields: true });
The above code works sometimes and sometimes it throws the below error
{
“error”: {
“code”: “UNEXPECTED_ERROR”,
“message”: “{\”type\”:\”error.SuiteScriptError\”,\”name\”:\”UNEXPECTED_ERROR\”,\”message\”:null,\”stack\”:[\”anonymous(N/serverRecordService)\”,\”doPost(/SuiteScripts/centime_post_transactions.js:189)\”],\”cause\”:{\”type\”:\”internal error\”,\”code\”:\”UNEXPECTED_ERROR\”,\”details\”:null,\”userEvent\”:null,\”stackTrace\”:[\”anonymous(N/serverRecordService)\”,\”doPost(/SuiteScripts/centime_post_transactions.js:189)\”],\”notifyOff\”:false},\”id\”:\”b77d0131-d14d-4535-bbc2-e097c075f100-2d323032322e30342e3036\”,\”notifyOff\”:false,\”userFacing\”:false}”
}
}
It fails at the line where we are calling vendorBillPayment.setSublistValue, and strangely sometimes it works.
Not able to understand what is the exact cause of this issue.
Any help or pointers to understand and resolve this issue would be really useful.