Trying to configure a record creation script in Netsuite. Just getting to grips with the basics.
I have created this script from the Netsuite docs with slight modification to make it relevant to my account.
It runs and says Complete, however no transaction is created and in the logs where I am trying to capture to document number it says 'To be generated'.
I followed all the oracle docs on this so not sure, any help appreciated.
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/runtime', 'N/record'], function(runtime, record) {
return {
execute: function(context) {
var objRecord = record.create({
type: record.Type.INVOICE,
isDynamic: true,
defaultValues: {
entity: 3413
}
});
objRecord.setValue({
fieldId: 'location',
value: 1
});
objRecord.selectNewLine({
sublistId: 'item'
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 190
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 2
});
objRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value: 2
});
var documentNum = objRecord.getValue({
fieldId: 'tranid'
});
log.debug({
title: 'New Invoice',
details: 'Record creation progress' + documentNum
});
}
};
});
You need to do objRecord.save() first, then the record will be saved and the tranid will be generated