最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How get fist set of thousand records and next set of thousand records using for loop in Netsuite 'Nsearch M

programmeradmin2浏览0评论

I want to process first set of thousand records and then next set of thousand records from the search results obtained from the Search Results .

i'm getting the first set of thousand records using the method available in suitescript 2.0 version'N/search' module's Method (getRange(0,1000)).

CODE:

var mySearch = search.load({
id: 'customsearch_employee'
});
var searchResult = mySearch.run().getRange(0, 100);
for (var i = 0; i < searchResult.length; i++) {
var entity = searchResult[i].getValue({
name: 'entity'
});
});

I want know how to process next set of thousand records using the for loops. thanks in advance

I want to process first set of thousand records and then next set of thousand records from the search results obtained from the Search Results .

i'm getting the first set of thousand records using the method available in suitescript 2.0 version'N/search' module's Method (getRange(0,1000)).

CODE:

var mySearch = search.load({
id: 'customsearch_employee'
});
var searchResult = mySearch.run().getRange(0, 100);
for (var i = 0; i < searchResult.length; i++) {
var entity = searchResult[i].getValue({
name: 'entity'
});
});

I want know how to process next set of thousand records using the for loops. thanks in advance

Share Improve this question asked Jul 29, 2016 at 4:42 Deepan MuruganDeepan Murugan 7813 gold badges22 silver badges42 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

SuiteScript 2.0 provides a paging API for you. I'll explain a bit first, and then show an example.

After you create your search object mySearch, instead of calling run(), you call runPaged() to run a paged search, which has an optional pageSize parameter that allows you to specify how many results per page. Default value is 50.

runPaged returns a PagedData object that contains the list of pages of results in its pageRanges property. You actually retrieve the results on each page by calling fetch on the page.

This example is taken straight from the Help page for N/search, but I've added some explanatory ments.

/**
 *@NApiVersion 2.x
 */
require(['N/search'], function(search) {
    function loadAndRunSearch() {
        // Load your search into memory
        var mySearch = search.load({
            id: 'customsearch_my_so_search'
        });

        // Run paged version of search with 1000 results per page
        var myPagedData = mySearch.runPaged({
            "pageSize": 1000
        });

        // Iterate over each page
        myPagedData.pageRanges.forEach(function(pageRange){

            // Fetch the results on the current page
            var myPage = myPagedData.fetch({index: pageRange.index});

            // Iterate over the list of results on the current page
            myPage.data.forEach(function(result){

                // Process the individual result
                var entity = result.getValue({
                    name: 'entity'
                });
                var subsidiary = result.getValue({
                    name: 'subsidiary'
                });
            });
        });
    }
    loadAndRunSearch();
});

You should be able to get the next range using :

var searchResult = mySearch.run().getRange(1000, 2000);

In a loop you can check the length and get all the results:

var searchResult = mySearch.run().getRange(0, 1000) || []; 
var i = 1000;
while(searchResult.length >= 1000){
i+= 1000;
searchResult = searchResult.concat((mySearch.run().getRange(i, i+1000) || []));
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论