I need to do following operation performed when my Map/Reduce suiteScript run. It search all sales order where status is Pending Fulfillment, and update their custom checkbox field (field key is my_custom_field_is_proccessed
).
How I am trying to do is like below;
/**
* @NApiVersion 2.0
* @NScriptType MapReduceScript
*/
define(['N/search', 'N/record'], function (search, record) {
function getInputData() {
var filter1 = search.createFilter({
name: 'orderstatus',
operator: search.Operator.IS,
values: 'Pending Fulfillment'
});
return search.create({
type: search.Type.SALES_ORDER,
columns: [],
filters: [filter1]
});
}
function map(context) {
try {
var data = JSON.parse(context.value); //read the data
var transId = data.tranid;
var orderstatus = data.orderstatus
var isProcessed = data.my_custom_field_is_proccessed
/*
var order = record.save({
'fromId':data.values['internalid'].value,
'my_custom_field_is_proccessed':true
});
*/
// Update as per below answer
data.forEach(function (order) {
var id = record.submitFields({
type: 'salesOrder',
id: order.internalid,
values: {
my_custom_field_is_proccessed: true
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
});
} catch (ex) {
log.error({ title: 'map: error saving records', details: ex });
}
}
function reduce(context) {
// your code here ...
}
function summarize(summary) {
// your code here ...
}
return {
getInputData: getInputData,
map: map,
reduce: reduce,
summarize: summarize
};
});
Use record.submitFields instead of record.save.