1

我试图从 SuiteScript 2.0 中的分页搜索中获取最后 200 个结果。当我运行简单的代码时,我得到了错误

"name":"INVALID_PAGE_RANGE","message":"无效的页面范围:获取。"

我到底做错了什么?

以下代码在 NS 调试器中运行(为简洁起见,我删除了一些代码):

function(ui, email, runtime, search, file, config, format, record, log) {

    var mySearch = search.load({
            id: 'customsearch_mht_lrf_export_to_lab'
        });

    // 200 results per page (am I correct here?)
    var results = mySearch.runPaged({pageSize:200});

    var count = results.count; // = 264

    // Obtain the last 200 results. From the documentation; 
    // index is 'The index of the page range that bounds the desired data.'
    // Error occurs on the next line
    var data = results.fetch({index: results.count});

    var x = 0;

});
4

1 回答 1

2

(我已经在 Slack 小组中回答了这个问题,但我会在此处复制我的答案,以防有一天有人遇到这个问题并看到该帖子)。

index您传递给的参数是results.fetch您想要的数据“页面”的索引。在上面的示例中,您有 264 个结果并且您的页面大小为 200,结果将有 2 页。结果 1 - 199 将在第一页(索引 = 0),200 - 264 在第二页。

为了获得最后 200 个结果,您将始终需要检索最后 2 页(除非结果计数是 200 的精确倍数),然后只查看这些结果中的最后 200 个。

于 2017-08-09T04:32:05.527 回答