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

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

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 文章 中所记录:

使用一个开发者定义的函数,在搜索结果中的每一行上调用,每次最多返回 4,000 个结果。

要克服这个限制,你可以:

  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-2.html
匿名

发表评论

匿名网友

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

确定