【发布时间】:2016-02-16 09:56:21
【问题描述】:
下面是我想出的代码,用于使用 SuiteScript 在 NetSuite 中运行保存的搜索,使用保存的搜索结果创建 CSV,然后通过电子邮件发送 CSV。问题是,结果限制为 1000 条记录。我已经研究过这个问题,看来解决方案是运行一个以 1000 为增量进行切片的循环。我认为用于切片搜索的示例也在下面。
但是,我似乎无法将切片合并到我的代码中。谁能帮我将切片代码与我的原始搜索代码结合起来?
var search = nlapiSearchRecord('item', 'customsearch219729');
// Creating some array's that will be populated from the saved search results
var content = new Array();
var cells = new Array();
var temp = new Array();
var x = 0;
// Looping through the search Results
for (var i = 0; i < search.length; i++) {
var resultSet = search[i];
// Returns an array of column internal Ids
var columns = resultSet.getAllColumns();
// Looping through each column and assign it to the temp array
for (var y = 0; y <= columns.length; y++) {
temp[y] = resultSet.getValue(columns[y]);
}
// Taking the content of the temp array and assigning it to the Content Array.
content[x] += temp;
// Incrementing the index of the content array
x++;
}
//Inserting headers
content.splice(0, 0, "sku,qty,");
// Creating a string variable that will be used as the CSV Content
var contents;
// Looping through the content array and assigning it to the contents string variable.
for (var z = 0; z < content.length; z++) {
contents += content[z].replace('undefined', '') + '\n';
}
// Creating a csv file and passing the contents string variable.
var file = nlapiCreateFile('InventoryUpdate.csv', 'CSV', contents.replace('undefined', ''));
// Emailing the script.
function SendSSEmail()
{
nlapiSendEmail(768, 5, 'Inventory Update', 'Sending saved search via scheduled script', 'cc@email.com', null, null, file, true, null, 'cc@email.com');
}
以下代码是我发现用于返回超过 1000 条记录的示例。同样,作为一个新手,我似乎无法将切片合并到我原来的、正常运行的 SuiteScript 中。任何帮助当然都非常感谢。
var filters = [...];
var columns = [...];
var results = [];
var savedsearch = nlapiCreateSearch( 'customrecord_mybigfatlist', filters, columns );
var resultset = savedsearch.runSearch();
var searchid = 0;
do {
var resultslice = resultset.getResults( searchid, searchid+1000 );
for (var rs in resultslice) {
results.push( resultslice[rs] );
searchid++;
}
} while (resultslice.length >= 1000);
return results;
【问题讨论】:
标签: netsuite