forEachResult()方法对返回的结果集限制为4000行。

huangapple go评论65阅读模式
英文:

forEachResult() method is limited to 4000 rows in the result set returned

问题

你好!我们的NetSuite suitelet脚本在返回的结果集中限制为4000行,你有什么办法可以使用forEachResult()方法来处理超过4000行的情况吗?

var resultNumber = 0;
studentRecordsObj.run().each(function(result){
  log.debug("processing row #", ++resultNumber);
  sponsorshipNumberField.addSelectOption({
    value: result.id,
    text: result.getValue({name: 'custrecord12'}) + ' ' + result.getValue({name: 'custrecord_name'}),
  });
  return true;
});

尝试使用其他方法来解决。谢谢!

英文:

Good day! our NetSuite suitelet script is limited to 4000 rows in the result set returned, any idea on how do we script to be able to more than 4000 rows using the forEachResult() method?

var resultNumber=0;
                studentRecordsObj.run().each(function(result){
                  log.debug("processing row #", ++resultNumber);
                    sponsorshipNumberField.addSelectOption({
                        value: result.id,
                        text: result.getValue({name: 'custrecord12'}) + ' ' + result.getValue({name: 'custrecord_name'}),
                    })
                    return true;
                })

trying to resolve using the other ideas. thank you

答案1

得分: 2

翻译结果

ResultSet.each(callback) 方法有一个限制,最多只能返回4,000个结果,详见此 SuiteAnswers 文章

> 使用开发者自定义的函数,在搜索结果中的每一行上调用,每次最多处理4000个结果。

要克服这个限制,你可以采取以下方法:

  1. 使用 Search.run().getRange() 方法按范围迭代完整的结果集,然后迭代每个范围中包含的结果。

  2. 使用 Search.runPaged() 方法,获取每个页面的数据并迭代结果。示例代码如下:

     var searchObj = searchObjSearch.runPaged({
         pageSize:1000
     });
     searchObj.pageRanges.forEach(function (pageRange) {
         searchObj.fetch({
             index:pageRange.index
         })
         .data.forEach(function (result) {
             // 在这里处理每个搜索结果
         });
     });
    

额外建议

在 Suitelet 中处理数千个结果可能会导致执行速度变慢并达到治理限制。此外,由于你似乎将结果添加到一个选择字段中,用户可能会觉得从如此多的选项中选择变得不方便。

考虑是否可以通过向保存的搜索添加筛选器或在 Suitelet 页面中添加动态筛选器来减少结果数量(通过动态筛选器,我指的是用户可以选择或输入一个值的字段,并在附加的客户端脚本中使用 fieldChanged() 事件使用该字段的值重新加载 Suitelet 时添加额外的筛选器)。

英文:

Answer

ResultSet.each(callback) has a limitation of 4,000 results, as documented in this SuiteAnswers article:

> Use a developer-defined function to invoke on each row in the search results, up to 4000 results at a time.

To overcome this limitation you can:

  1. Use Search.run().getRange() to iterate the full result set by range, and then iterate the results contained in each range.

  2. Use Search.runPaged(), fetch the data for each page and iterate the results. Example:

        var searchObj = searchObjSearch.runPaged({
            pageSize:1000
        });
        searchObj.pageRanges.forEach(function (pageRange) {
            searchObj.fetch({
                index:pageRange.index
            })
            .data.forEach(function (result) {
                //Process each search result here
            });
                csv.push(row);
                row = {};
            });
        });
    

Unsolicited Extra Advice

Processing thousands of results in a Suitelet may result in slow execution and hitting governance limits. Also, as it appears you are adding the results to a select field, users may find it unwieldy to select from so many options.

Consider whether you can reduce the number of results by adding a filter to the saved search or incorporating a dynamic filter within the Suitelet page (by this I mean a field that the user can select or enter a value, and a fieldChanged() event in an attached client script which then reloads the Suitelet using that field's value in an additional filter).

huangapple
  • 本文由 发表于 2023年8月9日 10:26:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864195.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定