Delete a record using Map Reduce
Map Reduce is an asynchronous type script which allow concurrent processing of records.
Given Sample delete a records satisfying a give search conditions
/**
* @NApiVersion 2.x
* @NScriptType MapReduceScript
* @NModuleScope SameAccount
*/
//--------------------------------------------------------
// delete the maint for all deleted opportunitites
//--------------------------------------------------------
define(['N/search', 'N/record'], function (search, record) {
var OPP = {
type: "opportunity",
maint: "custbody_jj_ismaintprocessed"
};
var MFR = {
type: "customrecord_esw_mfr_maint_file_table",
field: {
opportunity: "custrecord_esw_mfr_opportunity",
base: "custrecord_esw_mfr_base_usd",
listRate: "custrecord_esw_mfr_listrate_usd",
currency: "custrecord_esw_mfr_currency",
startDate: "custrecord_esw_mfr_start_date"
}
};
function deleteMaint(scriptContext) {
try {
record.delete({
id: scriptContext.key,
type: MFR.type
});
} catch (err) {
log.debug("error@deleteMaint", err);
}
}
return {
getInputData: function (scriptContext) {
return search.create({
type: MFR.type,
filters: [MFR.field.opportunity, "anyof", "@NONE@"],
columns: ["internalid"]
})
},
reduce: deleteMaint,
summarize:function(summary){
try {
log.debug('summary@summarize', summary);
} catch (err) {
log.debug('err@summarize', err);
}
}
}
});