2017-08-09 45 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個。