Hello! Can someone send me a basic example of a ma...
# suitescript
i
Hello! Can someone send me a basic example of a map reduce that uses a paginated search? or any documentation that can be usefull? Thanks in advanced!
s
Hello Iñaki, If the search is for the getInputData step and you are concerned about the number of results it will return, Netsuite does everything automatically if you return the search directly.
function getInputData(context) {
var searchObject = search.create({
type: "item",
filters: [["internalid", "anyof", "43276"], "AND", ["pricing.currency", "anyof", "1"]],
columns:
[
search.createColumn({ name: "pricelevel", join: "pricing" }),
search.createColumn({ name: "unitprice", join: "pricing" })
]
});
return searchObject;
}
In the Map step you will have all the available results
function map(context) {
log.debug('context', context);
const searchResult = JSON.parse(context.value);
context.write({
key: searchResult.values['pricelevel.pricing'].value,
value: searchResult.values['unitprice.pricing']
});
}
g
/** * @NApiVersion 2.x * @NScriptType MapReduceScript */ define(['N/search'], function(search) { function getInputData(context) { return search.create({ type: 'customer', columns: ['internalid', 'companyname'], filters: ['isinactive', 'is', 'F'] }).runPaged({pageSize: 100}); } function map(context) { var searchResult = JSON.parse(context.value); // process search result // ... } function reduce(context) { // not used in this example } function summarize(summary) { // not used in this example } return { getInputData: getInputData, map: map, reduce: reduce, summarize: summarize }; });
i
Thanks for the info!