gpt4 book ai didi

javascript - 在 SuiteScript 中提取 JSON 数据时出现问题 - NetSuite

转载 作者:行者123 更新时间:2023-12-01 02:16:57 28 4
gpt4 key购买 nike

我试图查看客户付款数据的“应用”子列表中的值是否已更改,并根据它执行一些操作。

我的SuiteScript如下:

define(['N/record', 'N/https'],
function(record,https)
{

function afterSubmit(context)
{
var oldRec = context.oldRecord;
log.debug({title: 'oldRec ', details: oldRec });
// This log shows that the JSON has an
// attribute called sublists which contains "apply" which has all the applied payments
// eg: {"id":"1234", "type":"customerpayment", "fields":{all the fields},
// "sublists": {"apply" : {"line 1"...}}}

var oldRecSublists = oldRec.sublists;
log.debug({title: 'oldRecApply ', details: oldRecSublists });
// This returns empty or null though there is data

我在这里做错了什么?

基本上我想要实现的是比较 context.oldRecord.sublists.apply 和 context.newRecord.sublists.apply 以查找 amt 是否已更改。

SuiteScript 2.0 有更好的方法吗?

提前致谢!

最佳答案

那里发生的部分情况是,看起来您正试图通过在 print 语句中看到的内容来解释 NS 数据结构。您根本没有使用 NS api。

当您将 NS 对象发送到日志函数时,我相信它会经历自定义 JSON.stringify 过程,因此如果您只想检查值,您可以执行以下操作:

var oldRecObj = JSON.parse(JSON.stringify(oldRec));

现在可以像检查一个简单对象一样检查oldRecObj。但你根本无法操纵它。

您应该使用NS schema browser

对N/record的操作参见帮助文档

我经常用于处理子列表的一个片段是:

function iter(rec, listName, cb){
var lim = rec.getLineCount({sublistId:listName});
var i = 0;
var getV = function (fld){
return rec.getSublistValue({sublistId:listName, fieldId:fld, line:i});
};
var setV = function(fld, val){
rec.setSublistValue({sublistId:listName, fieldId:fld, line:i, value:val});
};
for(; i< lim; i++){
cb(i, getV, setV);
}
}

然后

iter(oldRec, 'apply', function(idx, getV, setV){
var oldApplied = getV('applied');
});

关于javascript - 在 SuiteScript 中提取 JSON 数据时出现问题 - NetSuite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49438873/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com