how to get More than 1000 records in a search in Netsuite
Hi All,
Most of the time while creating reports common question is how we can get more than 1000 records in one search.
There are 2 simple api which we can directly and get result:
1.nlapiCreateSearch then runsearch and get 4000 records but we can use 1000 at one time
2. nlapiSearchRecord - we can use 1000 at one time .
This is Netsuite limit that we can search 1000 results in a single search.
Below are the methods how we can increase the limit:
Method 1: Sort By Internalid number and then search for record where internal ids are greater than oldest id from last run
Make a global variable and update that every time script go in for loop(you can change logic as per you need),
Now add a logic for next run, most of the time I add logic like
var lastprocessed = 0;
do
{
if(lastprocessed > 0)
{
add filter for internalidnumber greater than lastprocessed .
var searchresults = nlapiSearchRecord(......
for(var i=0; i <= searchresults.length; i++)
{
//add your logic here
lastprocessed= searchresults[i].getId();
}
}
//add search logic and filter
}while(searchresults.length == 1000);
Method 2: Records which are processed by script , add them to an array and then :
var itemids= [];//this item will have list of all items processed already. keeping this as global to avoid concatenating of processed ids.
var filters = [];
do()
{
if(itemids && (itemids.length > 0))
filters.push( new nlobjSearchFilter('internalid', null, 'noneof', itemids ) );
var searchRecordResults = nlapiSearchRecord( 'item',null, filters, null );
for(var i=0; i<searchRecordResults .length; i++)
{
var internlid = searchRecordResults[i].getId();
itemids.push(internalid);
}
}while(searchRecordResults .length == 1000);
***developer should change the value as per his/her need.
*** there may be error , Please let me know if I missed something.
Most of the time while creating reports common question is how we can get more than 1000 records in one search.
There are 2 simple api which we can directly and get result:
1.nlapiCreateSearch then runsearch and get 4000 records but we can use 1000 at one time
2. nlapiSearchRecord - we can use 1000 at one time .
This is Netsuite limit that we can search 1000 results in a single search.
Below are the methods how we can increase the limit:
Method 1: Sort By Internalid number and then search for record where internal ids are greater than oldest id from last run
Make a global variable and update that every time script go in for loop(you can change logic as per you need),
Now add a logic for next run, most of the time I add logic like
var lastprocessed = 0;
do
{
if(lastprocessed > 0)
{
add filter for internalidnumber greater than lastprocessed .
var searchresults = nlapiSearchRecord(......
for(var i=0; i <= searchresults.length; i++)
{
//add your logic here
lastprocessed= searchresults[i].getId();
}
}
//add search logic and filter
}while(searchresults.length == 1000);
Method 2: Records which are processed by script , add them to an array and then :
var itemids= [];//this item will have list of all items processed already. keeping this as global to avoid concatenating of processed ids.
var filters = [];
do()
{
if(itemids && (itemids.length > 0))
filters.push( new nlobjSearchFilter('internalid', null, 'noneof', itemids ) );
var searchRecordResults = nlapiSearchRecord( 'item',null, filters, null );
for(var i=0; i<searchRecordResults .length; i++)
{
var internlid = searchRecordResults[i].getId();
itemids.push(internalid);
}
}while(searchRecordResults .length == 1000);
***developer should change the value as per his/her need.
*** there may be error , Please let me know if I missed something.
Hello, A couple of things on the seconds script. the filter should be noneof, and the searchresults are not concatenated... Other than that, thanks!
ReplyDeleteThank you so much, yes you are right, did mistake while adding writing blog. Correcting now.
Delete