I am trying to modify a shipping order record using a netsuite script v2.
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(['N/search', 'N/record'],
function(search, record) {
function afterSubmit(context) {
if (context.type !== context.UserEventType.CREATE){
return;
}
try {
// Get the current Record
var salesOrder = context.newRecord;
salesOrder.setValue({fieldId: 'custbody_route_vendor', value: 1});
salesOrder.save({enableSourcing: true, ignoreMandatoryFields: true});
} catch (error) {
log.error({title: 'Error: ', details: error });
}
}
return {
afterSubmit: afterSubmit
};
});
This seems to be pretty straight forward. But when I save a sales order, it throws this error:
{"type":"error.SuiteScriptError","name":"THAT_RECORD_IS_NOT_EDITABLE","message":"That record is not editable.","stack":["createError(N/error)...
Which isn't very helpful because I don't know the types of things that would make a record uneditable.
I searched the docs and the internet, but can't find an reference for this error. The docs for that save function does not address possible errors:
.nl?fid=section_4267286323.html
Any suggestions would be very helpful.
I am trying to modify a shipping order record using a netsuite script v2.
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(['N/search', 'N/record'],
function(search, record) {
function afterSubmit(context) {
if (context.type !== context.UserEventType.CREATE){
return;
}
try {
// Get the current Record
var salesOrder = context.newRecord;
salesOrder.setValue({fieldId: 'custbody_route_vendor', value: 1});
salesOrder.save({enableSourcing: true, ignoreMandatoryFields: true});
} catch (error) {
log.error({title: 'Error: ', details: error });
}
}
return {
afterSubmit: afterSubmit
};
});
This seems to be pretty straight forward. But when I save a sales order, it throws this error:
{"type":"error.SuiteScriptError","name":"THAT_RECORD_IS_NOT_EDITABLE","message":"That record is not editable.","stack":["createError(N/error)...
Which isn't very helpful because I don't know the types of things that would make a record uneditable.
I searched the docs and the internet, but can't find an reference for this error. The docs for that save function does not address possible errors:
https://system.na2suite./app/help/helpcenter.nl?fid=section_4267286323.html
Any suggestions would be very helpful.
Share Improve this question asked May 2, 2019 at 17:22 Patrick_FinucanePatrick_Finucane 7551 gold badge7 silver badges25 bronze badges2 Answers
Reset to default 6The context
passed to the afterSubmit
function is read only. You cannot modify and then save the newly created record. You would need to either:
- Use the
beforeSubmit
function instead. UsingbeforeSubmit
allows you to change the record as you're doing, before it's submitted to the database - however, you should not callRecord.save()
on it, as the system will save the modified record after yourbeforeSubmit
pletes. - You can also use the
afterSubmit
function, but for this you need to load the record separately, modify it as required and then save.
I'll suggest using record.submitFields
in afterSubmit
instead of loading record and then saving it. It will save you execution units.
record.submitFields({
id: context.newRecord.id,
type: context.newRecord.type,
values: {'custbody_route_vendor' : '1'}
})