问题
I have tried to create invoice in the client script event.
var objRecord = record.create({
type: 'invoice',
isDynamic: false
});
objRecord.setValue({
fieldId: 'customform',
value: '296',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'account',
value: '215',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'entity',
value: '13276',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'currency',
value: '1',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'postingperiod',
value: '294',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'exchangerate',
value: '1.0',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'custbody_amortization_partner_currency',
value: '6',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'memo',
value: v_adv_memo,
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'custbody_amortization_advance_id',
value: v_advanceID,
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'trandate',
value: parsedDateStringAsRawDateObjectdtl,
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'duedate',
value: v_adv_pymt_pymt_date,
ignoreFieldChange: true
});
objRecord.selectNewLine({
sublistId: 'item'
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: '5825',
ignoreFieldChange: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: '1',
ignoreFieldChange: true
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value: '100',
ignoreFieldChange: true
});
objRecord.commitLine({
sublistId: 'item'
});
var recId = objRecord.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
alert(recId);
I am not sure where the error occurs. Can anyone help me on this topic ?
回答1:
Directly creating an invoice is not normally done. You would normally do either of the following. Note setting the custom form as part of the initialization is recommended for dynamic mode.
var invRec = record.transform({
fromType: record.Type.CUSTOMER,
fromId: custId,
toType: record.Type.INVOICE,
isDynamic: true,
defaultValues: {customform:296}
});
or
var invRec = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: soId,
toType: record.Type.INVOICE,
isDynamic: true,
defaultValues: {customform:296}
});
回答2:
I am having a similar issue, where I need to consolidate invoices and attach to their original sales orders and cannot do a transform.
Try using to get some information. log.debug({ title: 'Your title', details: 'Details: ' + objrecord.getValue({fieldId: 'otherrefnum'}) //for example });
I think the issue here is that NetSuite is expecting a type match. For example, rate cannot be accepted as a string - at least that's the TypeError that I'm getting.
Real-life example, where I pick all the fields from the invoice[i] and allocate it to consolidated invoice: INVALID_FLD_VALUE","message":"You have entered an Invalid Field Value 1092 for the following field: item" - most likely NetSuite is expecting an integer, not a string or vice versa.
Also, check the following link. Very useful to know which fields are mandatory in the invoice and which ones are not: http://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_2/script/record/invoice.html
来源:https://stackoverflow.com/questions/42939756/how-to-create-invoice-using-suitescript-2-0