gpt4 book ai didi

javascript - 脚本返回 'TypeError: cannot read property length from NULL',即使它不是

转载 作者:行者123 更新时间:2023-11-30 19:40:09 24 4
gpt4 key购买 nike

我正在尝试读取包含电子邮件 ID 的 CSV 文件,该文件将用作搜索过滤器以获取客户记录并从他们的记录中删除他们的电子邮件 ID。

这是我的代码

var context = nlapiGetContext();
var filedata = nlapiLoadFile(context.getSetting('SCRIPT', 'custscript42')).getValue().split(/\n|\n\r/);
for (var i = 0; i < filedata.length; i++) {
var email = filedata[i];
nlapiLogExecution('DEBUG', 'email', email);
var filters = new Array();
filters[0] = new nlobjSearchFilter('email', null, 'is', email);
var searchresults = nlapiSearchRecord('customer', null, filters, null);
nlapiLogExecution('DEBUG', '# of profiles with this email are:', searchresults.length);
for (var j = 0; searchresults != null && j < searchresults.length; j++) {
var id = searchresults[j].getId();
nlapiLogExecution('DEBUG', 'cleaning email for: ', id);
var record = nlapiLoadRecord('customer', id);
record.setFieldValue('email', '');
nlapiSubmitRecord(record);
nlapiLogExecution('DEBUG', 'Result', 'Success');
}
}

我不明白为什么 searchresults 被设置为 NUll,我尝试通过 UI 进行搜索以查看它是否适用于特定的电子邮件地址以及它是否适用于脚本。

有人有什么想法吗?

最佳答案

尝试使用 nlapiSearchRecord('entity'.... 而不是 customer。

客户是记录类型,但是搜索类型是实体

在搜索中,添加类型为 customer 的过滤器

https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2018_1/script/record/entity.html

另外,从管理的 Angular 来看,您最好使用 nlapiSubmitField 而不是加载/保存客户记录。

关于javascript - 脚本返回 'TypeError: cannot read property length from NULL',即使它不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55485166/

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