无法在 Suitescript 2.0 中创建笔记记录,但在 1.0 中可以

Can't create note record in Suitescript 2.0 but can in 1.0

任何人都知道为什么在客户端 SuiteScript 2.0 中,此代码给出错误 "Invalid transaction reference key 8355" 但是当我 运行 在 1.0 风格中进行相同的调用时,它可以工作。有人知道为什么吗?

SuiteScript 2.0(失败)

require(['N/record'], function(record){

    var note = record.create({type: 'note'});
    note.setValue({fieldId: 'title', value: 'Test'});
    note.setValue({fieldId: 'note', value: 'note description'});
    note.setValue({fieldId: 'notetype', value: 7});
    note.setValue({fieldId: 'transaction', value: 8355});
    note.save();
})

SuiteScript 1.0(有效)

var record = nlapiCreateRecord('note');
record.setFieldValue('title', 'Test' );
record.setFieldValue('note', 'note description');
record.setFieldValue('notetype',7 );
record.setFieldValue('transaction',8355);
var recordId = nlapiSubmitRecord(record);

1.0 客户端 SuiteScript 运行 没问题。

我可以确认我刚刚使用了您的代码(除了切换票据类型和交易字段以匹配我的账户)并且它工作正常。我在销售订单的控制台中执行了我的测试,所以它应该在客户端 suitescript 中工作得很好。您收到的错误是什么?我会仔细检查您的票据类型和交易价值是否有效。另外,您的脚本部署是什么样的,可能那里有问题?

另一件事,您在代码块末尾遗漏了一个“)”,但我认为这是复制粘贴错误。

这对我有用:

require(['N/record'], function (record) {
    var note = record.create({type: 'note'});
    note.setValue({fieldId: 'title', value: 'Test'});
    note.setValue({fieldId: 'note', value: 'note description'});
    note.setValue({fieldId: 'notetype', value: 7});
    note.setValue({fieldId: 'transaction', value: 453});
    note.save();
});