使用RESTlet在Netsuite中逐页获取记录 [英] Get records by page wise in Netsuite using RESTlet
问题描述
我想获取特定记录类型的所有记录,但是我只有1000条. 这是我使用的代码.
i want to get all the records in particular record type , but i got 1000 only. This is the code I used.
function getRecords() {
return nlapiSearchRecord('contact', null, null, null);
}
我需要两个代码.
1)一次获取全部记录
1) Get whole records at a single time
2)通过将pageindex作为参数传递给getRecords [1st => 0-1000,2nd => 1000-2000,...........]
2) Get the records page wise by passing pageindex as an argument to the getRecords [1st =>0-1000 , 2nd =>1000 - 2000 , ...........]
function getRecords(pageIndex) {
.........
}
预先感谢
推荐答案
您一次无法获取完整的记录.但是,您可以按internalid对结果进行排序,并记住第一个搜索结果的最后一个internalId,并在下一个搜索结果中使用其他过滤器.
you can't get whole records at a time. However, you can sort results by internalid, and remember the last internalId of 1st search result and use an additional filter in your next search result.
var totalResults = [];
var res = nlapiSearchRecord('contact', null, null, new nlobjSearchColumn('internalid').setSort()) || [];
lastId = res[res.length - 1].getId();
copyAndPushToArray(totalResult, res);
while(res.length < 1000)
{
res = nlapiSearchRecord('contact', null, ['internalidnumber', 'greaterthan', lastId], new nlobjSearchColumn('internalid').setSort());
copyAndPushToArray(totalResult, res);
lastId = res[res.length - 1].getId();
}
请注意,如果记录数量很多,则可能会在时间和使用点方面过度使用治理限制.
Beware, if the number of records are high you may overuse governance limit in terms of time and usage points.
如果您还记得lastId,则可以在RESTlet中编写逻辑以将id用作参数,然后将其用作附加过滤器以返回nextPage.
If you remember the lastId you can write a logic in RESTlet to take id as param and then use that as additional filter to return nextPage.
您可以编写逻辑以获取第n个pageresult,但您可能不得不无用地运行搜索n-1次.
You can write a logic to get nth pageresult but, you might have to run search uselessly n-1 times.
此外,我建议使用nlapiCreateSearch().runSearch()
,因为它最多可以返回4000条记录
Also, I would suggest to use nlapiCreateSearch().runSearch()
as it can return up to 4000 records
这篇关于使用RESTlet在Netsuite中逐页获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!