我是NetSuite的新手,所以请保持温柔。
我有一个简单的脚本,其目的是删除特定搜索返回的所有引号。
这里是:
function executeSavedSearch()
{
var searchresults = nlapiSearchRecord('estimate', 1234, null, null);
for (var i = 0; searchresults != null && i < searchresults.length; i++)
{
var searchresult = searchresults[i];
nlapiDeleteRecord(searchresults[i].getRecordType(), searchresults[i].getId());
}
}
就是这样。但是,每次运行它都会失败,并且执行日志会显示RCRD_DSNT_EXIST,详细信息为“该记录不存在。”
我已经确认搜索ID(上面的1234)正确无误了很多次。搜索返回许多记录,因此并不是没有结果可运行脚本。
非常感谢收到任何帮助。
答案 0 :(得分:0)
能否请您共享“保存的搜索”过滤器和列?可能没有设置主线/税线/运输线。这会导致在“事务的已保存搜索”中显示多行。
答案 1 :(得分:0)
尝试一下。
var estimateSearch = nlapiSearchRecord("estimate", null,
[
// add or remove filters as per your need.
["formulanumeric: {internalid}", "between", "200", "300"],
"AND",
["mainline", "is", "T"] // In order to avoid duplicate records in result, do not remove this filter
],
[
new nlobjSearchColumn("internalid") // Result column
]
);
var quoteId;
for (var i = 0; estimateSearch != null && i < estimateSearch.length; i++) {
quoteId = estimateSearch[i].getValue('internalid');
nlapiLogExecution("Debug", "Quote ID: " + quoteId, " Index: " + i);
// nlapiDeleteRecord('Estimate', quoteId); // Verify the Execution Logs before you uncomment this line of code.
}
我希望这会有所帮助。
答案 2 :(得分:0)
谢谢,锡德。正如您所建议的那样,通过一些错误记录,我将其范围缩小到了对nlapiDeleteRecord的实际调用。这是我的循环:
for (var i = 0; searchresults != null && i < searchresults.length; i++)
{
try
{
nlapiLogExecution("Debug", "About to delete record id " + searchresults[i].getId());
nlapiDeleteRecord(searchresults[i].getRecordType(), searchresults[i].getId());
}
catch (err)
{
var errMessage = err;
if(err instanceof nlobjError)
{
errMessage = errMessage + ' ' + err.getDetails() + ' ' + 'Failed to Delete ID : ' + id;
}
nlapiLogExecution('ERROR', 'Error', errMessage);
return err
}
}
它记录的ID和在错误消息中显示的ID相同-因此它记录“关于删除记录ID 1234”,然后给出错误消息:
代码:RCRD_DSNT_EXIST详细信息:该记录不存在。该记录不存在。删除ID失败:1234
但是当我运行保存的搜索时,我发现它实际上已经 删除了记录1234。下一次我运行它时,它会吐出相同的消息-但是ID为1235。然后它将被删除1235。这似乎是由于某种原因,它试图删除两次,第一次成功,然后第二次失败,因为已经被删除。
我已经反复检查了搜索-每个引号没有多行。如果在删除了删除行的情况下运行以上命令,我将得到预期的结果-搜索中每个ID的日志条目。
有什么建议吗?
答案 3 :(得分:0)
下次,请尝试在脚本调试器中运行脚本。您可以在脚本调试器中轻松跟踪此错误的原因。