Netsuite 脚本:是什么原因导致 THAT_RECORD_IS_NOT_EDITABLE 错误?
Netsuite Script: what causes THAT_RECORD_IS_NOT_EDITABLE error?
我正在尝试使用 netsuite 脚本 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
};
});
这似乎很简单。但是当我保存销售订单时,它会抛出这个错误:
{"type":"error.SuiteScriptError","name":"THAT_RECORD_IS_NOT_EDITABLE","message":"That record is not editable.","stack":["createError(N/error)...
这不是很有帮助,因为我不知道会使记录不可编辑的类型。
我搜索了文档和互联网,但找不到此错误的参考。该保存功能的文档未解决可能的错误:
https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4267286323.html
任何建议都会很有帮助。
传递给afterSubmit
函数的context
是只读的。您不能修改然后保存新创建的记录。您需要:
- 请改用
beforeSubmit
函数。使用 beforeSubmit
允许您在将记录提交到数据库之前更改记录 - 但是,您不应该对其调用 Record.save()
,因为系统将在您的 beforeSubmit
完成。
- 也可以使用
afterSubmit
功能,但需要单独加载记录,根据需要修改后保存。
我建议在 afterSubmit
中使用 record.submitFields
而不是加载记录然后保存它。它将为您节省执行单元。
record.submitFields({
id: context.newRecord.id,
type: context.newRecord.type,
values: {'custbody_route_vendor' : '1'}
})
我正在尝试使用 netsuite 脚本 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
};
});
这似乎很简单。但是当我保存销售订单时,它会抛出这个错误:
{"type":"error.SuiteScriptError","name":"THAT_RECORD_IS_NOT_EDITABLE","message":"That record is not editable.","stack":["createError(N/error)...
这不是很有帮助,因为我不知道会使记录不可编辑的类型。
我搜索了文档和互联网,但找不到此错误的参考。该保存功能的文档未解决可能的错误:
https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=section_4267286323.html
任何建议都会很有帮助。
传递给afterSubmit
函数的context
是只读的。您不能修改然后保存新创建的记录。您需要:
- 请改用
beforeSubmit
函数。使用beforeSubmit
允许您在将记录提交到数据库之前更改记录 - 但是,您不应该对其调用Record.save()
,因为系统将在您的beforeSubmit
完成。 - 也可以使用
afterSubmit
功能,但需要单独加载记录,根据需要修改后保存。
我建议在 afterSubmit
中使用 record.submitFields
而不是加载记录然后保存它。它将为您节省执行单元。
record.submitFields({
id: context.newRecord.id,
type: context.newRecord.type,
values: {'custbody_route_vendor' : '1'}
})