因此,我尝试使用 SuiteScript 1.0 在我的 NetSuite 实例上创建项目收据,但收到此错误消息:
{\"success\":false,\"errorMessage\":\"\\nCode: SSS_INVALID_SUBLIST_OPERATION\\nDetails: You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.\"}"
所以,我对NetSuite不太了解,但我认为静态列表不能修改。如果是这样的话,如果我无法添加项目,我该如何通过 SuiteScript 创建项目收据?
下面是我的脚本,以及我正在使用的 Postman Json 请求:
套件脚本:
function createItemReceipt(dataIn) {
try {
var record = nlapiCreateRecord('itemreceipt', {recordmode: 'dynamic'});
record.setFieldValue('entity', dataIn.entity);
for (var i = 0; i < dataIn.items.length; i++) {
var item = dataIn.items[i];
record.selectNewLineItem('item');
record.setCurrentLineItemValue('item', 'item', item.itemId);
record.setCurrentLineItemValue('item', 'quantity', item.quantity);
record.commitLineItem('item');
}
var recordId = nlapiSubmitRecord(record, true, true);
return {
success: true,
recordId: recordId
};
} catch (e) {
return {
success: false,
errorMessage: e.toString()
};
}
}
function post(dataIn) {
var response = createItemReceipt(dataIn);
return JSON.stringify(response);
}
Json 负载:
{
"entity": "123",
"items": [
{
"itemId": "456",
"quantity": 10
},
{
"itemId": "789",
"quantity": 5
}
]
}
NetSuite 中的项目收据很少(如果有的话)作为独立记录创建。创建它们的典型方式是“转换”采购订单或转移订单。为此,请使用 nlapiTransformRecord(type, id, transformType, transformValues)
而不是
nlapiCreateRecord
。SS1.0 的文档已从 SuiteAnswers HTML 中删除并打包为 PDF 参考。可以在 https://{{accountid}}.app.netsuite.com/help/helpcenter/shared_resources/PDF/SuiteScript10API.pdf?whence= 找到。在那里搜索nlapiTransformRecord
。
我已经部分复制了下面的相关部分,但文档还有更多内容,包括示例 - 所以如果可以的话也可以查找一下。nlapiTransformRecord(类型,id,transformType,transformValues)
使用现有记录中的数据初始化新记录 不同的类型并返回一个 nlobjRecord。这个功能很有用 用于自动订单处理,例如创建项目履行 订单中的交易和发票。
此 API 支持 客户端、用户事件、计划和 Suitelet 脚本。查看帮助 主题 SuiteScript 1.0 与此 API 相关的单位成本的 API 治理。
有关支持的转换类型的列表,请参阅支持的转换类型。
参数
type {string} [必需] - 记录内部 ID 名称。 在 NetSuite 帮助中心,请参阅帮助主题 SuiteScript 支持 记录。内部 ID 显示在名为“记录内部”的列中 身份证”。
- id {int} [必需] - 记录的internalId,用于 例如 555 或 78。
- transformType {string} [必需] - 记录 您正在转换现有记录的内部 ID 名称 记录到
- transformValues {hashtable} [可选] - 字段名称数组 -> 包含字段默认值的值对 用于转换。请注意,您还可以指定是否要进行记录转换 以动态模式发生。有关详细信息,请参阅帮助主题 SuiteScript 1.0 使用记录: 动态模式。