We have a series of expense reports that users want a BillPay record automatically created when they are Approved.
I have attempted to write this code multiple ways, multiple times and are consistently presented with 1 of 2 error messages in the debugger, UI, and/or log.
1. You must enter at least one line item for this transaction.
2. You have attempted an invalid sublist or line item operation. You are either trying to cannot access a field on a non-existent line or you are trying to add or remove lines from a static sublist.
:h_a_w:
Any Help Would Be Greatly Appreciated!
Attempt 1:
function afterSubmit_createRecord(type){ if (type == 'create') return; var expReportRec = nlapiLoadRecord('expensereport', nlapiGetRecordId()); var newVendorPaymentRec = nlapiCreateRecord('vendorpayment', {recordmode: 'dynamic'}); nlapiLogExecution('DEBUG', 'entity',expReportRec.getFieldValue('entity')); newVendorPaymentRec.setFieldValue('entity', expReportRec.getFieldValue('entity')); newVendorPaymentRec.setFieldValue('account', '212'); newVendorPaymentRec.setFieldValue('total', expReportRec.getFieldValue('total')); newVendorPaymentRec.setFieldValue('unapplied','0.00'); newVendorPaymentRec.setLineItemValue('apply', 'apply', 1, 'T'); newVendorPaymentRec.setLineItemValue('apply', 'disc', 1, '1'); var id = nlapiSubmitRecord(newVendorPaymentRec, true, true); nlapiLogExecution('DEBUG', 'afterSubmit_createRecord', 'Create New Vendor Payment record id <' + id + '>'); }Attempt 2:function afterSubmit_createRecord(type){ try { if (type == 'create') return; var expReportRec = nlapiLoadRecord('expensereport',VendorPaymentRec = nlapiCreateRecord('vendorpayment', {recordmode: 'dynamic'})); nlapiLogExecution('DEBUG', 'entity',expReportRec.getFieldValue('entity')); newVendorPaymentRec.setFieldValue('entity', expReportRec.getFieldValue('entity')); newVendorPaymentRec.setFieldValue('account', '382'); newVendorPaymentRec.setFieldValue('total', expReportRec.getFieldValue('total')); newVendorPaymentRec.setFieldValue('unapplied','0.00'); newVendorPaymentRec.setFieldValue('trandate', expReportRec.getFieldValue('trandate')); //newVendorPaymentRec.setFieldValue('autoapply','F'); newVendorPaymentRec.insertLineItem('apply', 1); newVendorPaymentRec.setLineItemValue('apply', 'apply', 1, 'T'); newVendorPaymentRec.setLineItemValue('apply', 'doc', 1, '227'); //newVendorPaymentRec.setLineItemValue('apply', 'due', 1, '0'); newVendorPaymentRec.setLineItemValue('apply', 'disc', 1, '1'); //newVendorPaymentRec.setLineItemValue('apply', 'line', 1, 0); var id = nlapiSubmitRecord(newVendorPaymentRec, true, true); nlapiLogExecution('DEBUG', 'afterSubmit_createRecord', 'Create New Vendor Payment record id <' + id + '>'); } catch (e) { var stErrMsg = ''; if (e.getDetails != undefined) { stErrMsg = 'Script Error: ' + e.getCode() + '<br>' + e.getDetails() + '<br>' + e.getStackTrace(); } else { stErrMsg = 'Script Error: ' + e.toString(); } nlapiLogExecution('ERROR', 'Script Error', stErrMsg); } } Attempt 3:function afterSubmit_createRecord(type) { try { if (type != 'create') return; var expReportRec = nlapiLoadRecord('expensereport', nlapiGetRecordId()); //if (expReportRec.getFieldValue('custbody_to_create') != 'T') return; var newVendorPaymentRec = nlapiCreateRecord('vendorpayment'); newVendorPaymentRec.setFieldValue('account', '1'); newVendorPaymentRec.setFieldValue('entity', expReportRec.getFieldValue('entity')); newVendorPaymentRec.setFieldValue('total', expReportRec.getFieldValue('total')); newVendorPaymentRec.setFieldValue('trandate', expReportRec.getFieldValue('trandate')); newVendorPaymentRec.setFieldValue('autoapply','F'); // newVendorPaymentRec.selectNewLineItem('apply'); // newVendorPaymentRec.setCurrentLineItemValue('apply', 'apply', 'T'); // newVendorPaymentRec.setCurrentLineItemValue('apply', 'applydate', nlapiDateToString(new Date())); // newVendorPaymentRec.setCurrentLineItemValue('apply', 'doc', '227'); // newVendorPaymentRec.commitLineItem('apply'); newVendorPaymentRec.insertLineItem('apply', 1); newVendorPaymentRec.setLineItemValue('apply', 'applapply', 1, 'T') newVendorPaymentRec.setLineItemValue('apply', 'appldoc', 1, '227'); newVendorPaymentRec.setLineItemValue('apply', 'appldue', 1, '10'); newVendorPaymentRec.setLineItemValue('apply', 'appldisc', 1, '1'); newVendorPaymentRec.setLineItemValue('apply', 'applline', 1, 0); var id = nlapiSubmitRecord(newVendorPaymentRec, true, true) nlapiLogExecution('DEBUG', 'afterSubmit_createRecord', 'Create New Vendor Payment record id <' + id + '>'); } catch (e) { var stErrMsg = ''; if (e.getDetails != undefined) { stErrMsg = 'Script Error: ' + e.getCode() + '<br>' + e.getDetails() + '<br>' + e.getStackTrace(); } else { stErrMsg = 'Script Error: ' + e.toString(); } nlapiLogExecution('ERROR', 'Script Error', stErrMsg); } } Attempt 4:function expense_SaveRecord() { var newVendorPaymentRec = nlapiCreateRecord('vendorpayment', {recordmode: 'dynamic'}); newVendorPaymentRec.setFieldValue('entity', '896'); newVendorPaymentRec.setFieldValue('account', '212'); newVendorPaymentRec.setFieldValue('accttype', 'Bank'); newVendorPaymentRec.setFieldValue('apacct', '382'); newVendorPaymentRec.setFieldValue('billpay', 'F'); //newVendorPaymentRec.setFieldValue('billpayCheckNumber', 'To Bill Pay'); //newVendorPaymentRec.setFieldValue('companyid', '896'); newVendorPaymentRec.setFieldValue('currency', '1'); newVendorPaymentRec.setFieldValue('currencyprecision', '2'); newVendorPaymentRec.setFieldValue('customform', '110'); newVendorPaymentRec.setFieldValue('entitynexus', '1'); newVendorPaymentRec.setFieldValue('exchangerate', '1.00'); newVendorPaymentRec.setFieldValue('subsidiary', '13'); //newVendorPaymentRec.insertLineItem('apply', 1); newVendorPaymentRec.setLineItemValue('apply', 'amount', 1, '130.48'); newVendorPaymentRec.setLineItemValue('apply', 'apply', 1, 'T'); newVendorPaymentRec.setLineItemValue('apply', 'currency', 1, 'USD'); newVendorPaymentRec.setLineItemValue('apply', 'doc', 1, '34963'); newVendorPaymentRec.setLineItemValue('apply', 'due', 1, '130.48'); newVendorPaymentRec.setLineItemValue('apply', 'internalid', 1, '34963'); newVendorPaymentRec.setLineItemValue('apply', 'line', 1, '0'); newVendorPaymentRec.setLineItemValue('apply', 'refnum', 1, 'EXP0000355'); newVendorPaymentRec.setLineItemValue('apply', 'total', 1, '130.48'); newVendorPaymentRec.setLineItemValue('apply', 'type', 1, 'Expense Report'); var id = nlapiSubmitRecord(newVendorPaymentRec); var debug = 1; return true; //var ExpenseData = nlapiLoadRecord('expensereport', nlapiGetRecordId()); var expReportRec = nlapiLoadRecord('expensereport', '113'); var newVendorPaymentRec = nlapiCreateRecord('vendorpayment', {recordmode: 'dynamic'}); newVendorPaymentRec.setFieldValue('entity', expReportRec.getFieldValue('entity')); newVendorPaymentRec.setFieldValue('account', '382'); newVendorPaymentRec.setFieldValue('exchangerate', '1.00'); newVendorPaymentRec.setFieldValue('currency', 'USA'); newVendorPaymentRec.setFieldValue('total', expReportRec.getFieldValue('total')); newVendorPaymentRec.setFieldValue('unapplied','0.00'); newVendorPaymentRec.setFieldValue('trandate', expReportRec.getFieldValue('trandate')); //newVendorPaymentRec.setFieldValue('autoapply','F'); newVendorPaymentRec.insertLineItem('apply', 1); newVendorPaymentRec.setLineItemValue('apply', 'apply', 1, 'T'); newVendorPaymentRec.setLineItemValue('apply', 'doc', 1, '227'); //newVendorPaymentRec.setLineItemValue('apply', 'due', 1, '0'); newVendorPaymentRec.setLineItemValue('apply', 'disc', 1, '1'); //newVendorPaymentRec.setLineItemValue('apply', 'line', 1, 0); var id = nlapiSubmitRecord(newVendorPaymentRec, true, true); var x = 0; return true; }