{"type":"error.SuiteScriptError","name":"DATE_EXPECTED","message":"You entered 'null' into a field where a calendar date was expected.\\nPlease go back and change this value to the correct date.","id":"","stack":["Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)\n at createInvoices (/SuiteScripts/Pending_RMAs_Invoices.js:151:43)\n at Object.onRequest (/SuiteScripts/Pending_RMAs_Invoices.js:12:17)"],"cause":{"type":"internal error","code":"DATE_EXPECTED","details":"You entered 'null' into a field where a calendar date was expected.\\nPlease go back and change this value to the correct date.","userEvent":null,"stackTrace":["Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)\n at createInvoices (/SuiteScripts/Pending_RMAs_Invoices.js:151:43)\n at Object.onRequest (/SuiteScripts/Pending_RMAs_Invoices.js:12:17)"],"notifyOff":false},"notifyOff":false,"userFacing":true}
function createInvoices(context) {
const request = context.request;
const lineCount = request.getLineCount({ group: 'custpage_rma_list' });
const itemFromScriptParam = runtime.getCurrentScript().getParameter({
name: 'custscript_fs_rma_invoice_item'
});
// log.debug("rmaList", {linecount: lineCount, itemFromScriptParam: itemFromScriptParam, request: request});
for (let i = 0; i < lineCount; i++) {
const isSelected = request.getSublistValue({ group: 'custpage_rma_list', name: 'custpage_select', line: i });
if (isSelected !== 'T') continue;
const rma = request.getSublistValue({ group: 'custpage_rma_list', name: 'custpage_rma_id', line: i });
const billAmount = request.getSublistValue({ group: 'custpage_rma_list', name: 'custpage_bill_amount', line: i });
log.debug("Invoice For", { rma: rma, billAmount: billAmount });
const invoice = record.create({
type: record.Type.INVOICE,
isDynamic: true,
defaultValues: { customform: 141 }
});
const allFields = invoice.getFields();
const dateFields = [];
allFields.forEach(fieldId => {
let value = invoice.getValue({ fieldId });
if (value instanceof Date) {
dateFields.push(fieldId);
}
});
log.debug("Date Fields in Invoice", dateFields);
invoice.setValue({ fieldId: 'entity', value: request.getSublistValue({ group: 'custpage_rma_list', name: 'custpage_customer_id', line: i }) });
invoice.setValue({ fieldId: 'subsidiary', value: 29 })
invoice.setValue({ fieldId: 'approvalstatus', value: 1 })
invoice.setValue({ fieldId: 'asofdate', value: format.parse({ value: new Date(), type: format.Type.DATE }) })
invoice.setValue({ fieldId: 'trandate', value: format.parse({ value: new Date(), type: format.Type.DATE }) })
invoice.selectNewLine({ sublistId: 'item' });
invoice.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: itemFromScriptParam });
invoice.setCurrentSublistValue({ sublistId: 'item', fieldId: 'quantity', value: 1 });
invoice.setCurrentSublistValue({ sublistId: 'item', fieldId: 'rate', value: billAmount });
invoice.setCurrentSublistValue({ sublistId: 'item', fieldId: 'custcol_rev_start_date', value: format.parse({ value: new Date(), type: format.Type.DATE }) })
invoice.setCurrentSublistValue({ sublistId: 'item', fieldId: 'custcol_rev_end_date', value: format.parse({ value: new Date(), type: format.Type.DATE }) })
const subrec = invoice.getCurrentSublistSubrecord({ sublistId: 'item', fieldId: 'inventorydetail' });
subrec.selectNewLine({ sublistId: 'inventoryassignment' });
subrec.setCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'quantity', value: 1 });
subrec.setCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'issueinventorynumber', value: 11077 }); // 233R139842
subrec.commitLine({ sublistId: 'inventoryassignment' });
invoice.commitLine({ sublistId: 'item' });
const invoiceId = invoice.save({ ignoreMandatoryFields: true });
log.debug("Invoice Saved Successfully", invoiceId);
log.debug('Invoice Created', 'Invoice ID: ' + invoiceId);
context.response.write({ output: 'Invoices created successfully!' });
}
}
return { onRequest: onRequest };
});