2017-08-09 62 views
1

我试图从SuiteScript 2.0中的分页搜索中获取最后200个结果。当我运行简单代码时出现错误从页面搜索中提取最后n个结果

“name”:“INVALID_PAGE_RANGE”,“message”:“无效的页面范围:fetch。”

我究竟做错了什么?

下面的代码是在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; 

}); 

回答

2

(我已经回答了这个在松弛组,但我会在这里复制我的答案如果有人有一天有这个问题,并遇到帖子)。

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

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