我已经在Map / Reduce脚本的getInputData方法中加载了搜索。 并尝试在getInputData方法上运行Map方法上的搜索。
在用户事件,预定脚本,客户端脚本,套装脚本等常规脚本中,我们可以创建搜索并使用run()或runPaged()方法运行搜索。
我的问题是搜索能够使用getInputData方法中的run()或runPaged()方法或Map / Reduce脚本的Map方法运行吗?
If表示如何将搜索结果列传递给Map或Reduce的下一个阶段。
我的代码:
define(['N/error', 'N/record', 'N/search', 'N/log', 'N/task', 'N/runtime', 'N/email'],
/**
* @param {email} email
* @param {record} record
* @param {runtime} runtime
* @param {search} search
* @param {task} task
* @param {transaction} transaction
*/
/* this script is used to create the search on the invoice and store the obtained search results on the object and trying to create the another search based on the values on the object */
function(error, record, search, log, task, runtime, email) {
function getInputData() {
log.debug("Get Input", "Initiated");
//Invoice Search
var invoiceSearch = search.load({
id: 'customsearch_invoice_calc'
});
log.debug("invoiceSearch:", invoiceSearch);
//Creating the Object for Storing Search Results
var invoiceDetails = {};
var invoiceId = "Id";
var invoiceLineId = "invoiceLineId";
//Running the Search
var myPagedData = invoiceSearch.runPaged({
"pageSize": 1000
});
log.debug('myPagedData:', myPagedData);
myPagedData.pageRanges.forEach(function(pageRange) {
// Fetch the results on the current page
var myPage = myPagedData.fetch({
index: pageRange.index
});
log.debug('myPage:', myPage);
// Iterate over the list of results on the current page
myPage.data.forEach(function(result) {
// Process the individual result
invoiceDetails[invoiceId] = result.getValue({
name: 'internalid'
});
invoiceDetails[invoiceLineId] = result.getValue({
name: 'line'
});
});
})
log.debug("invoiceDetails:", invoiceDetails);
return invoiceSearch;
}
function map(context) {
log.debug("Map", "Initiated");
var searchResult = JSON.parse(context.value);
var invoiceId = searchResult.id;
var lineId = searchResult.values.line.value;
log.debug("invoiceId:", invoiceId);
log.debug("lineId:", lineId);
comCalulation(invoiceId, invoiceId);
context.write(invoiceId);
}
function commissionCalc(invoiceId, lineId) {
log.debug("Entered:", "Commission Calc Function");
log.debug("invoiceId - Inside Commission Calc:", invoiceId);
}
function reduce(context) {
log.debug("Reduce", "Initiated");
}
function summarize(summary) {
log.debug("summarize", "Initiated");
}
提前感谢。
答案 0 :(得分:3)
如果您只想将搜索结果从getInputData
传递给map
,那么您需要做的就是从getInputData
返回搜索对象。 NetSuite将自动执行搜索并将结果分发到map
或reduce
阶段,具体取决于您配置地图/缩小脚本记录的方式。
在NS帮助的标题为" Map / Reduce Script Type"的页面中给出了一个例子。 as"例2&#34 ;;我在这里复制了部分内容:
function getInputData()
{
// Input phase only needs to create/load and return search object
return search.create({
type: record.Type.INVOICE,
filters: [['status', search.Operator.IS, 'open']],
columns: ['entity'],
title: 'Open Invoice Search'
});
}
function map(context)
{
// Parse individual search result
var searchResult = JSON.parse(context.value);
var invoiceId = searchResult.id;
var entityId = searchResult.values.entity.value;
applyLocationDiscountToInvoice(invoiceId);
// Pass customerId:invoiceId to the reduce phase
context.write(entityId, invoiceId);
}
您可以看到每个搜索结果都将作为context.value
传递,并需要解析为对象。每个搜索结果都会调用map
一次。