Good afternoon.
I am trying to get a User Event script to call or use a Map Reduce script. I am really new to the concept of a Map Reduce script and am not having much luck finding resources. Essentially, what I want to do is call a Map Reduce script that finds open transactions with the same Item Name and sets the Class on that item to the new item set by the User. The Map Reduce script would need to the Item Name and Class from the current record.
Here is my User Event:
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(['N/record', 'N/log'],
function (record, log) {
function setFieldInRecord (scriptContext) {
log.debug({
'title': 'TESTING',
'details': 'WE ARE IN THE FUNCTION!'
});
if (scriptContext.type === scriptContext.UserEventType.EDIT) {
var old_Record = scriptContext.oldRecord;
var cur_Record = scriptContext.newRecord;
var oldClassId = old_Record.getValue({ fieldId: 'class'});
var curClassId = cur_Record.getValue({ fieldId: 'class'});
if ( oldClassId != curClassId ) {
// CALL MAP REDUCE HERE
}
}
}
return {
beforeSubmit: setFieldInRecord
};
}
);
Is the Map Reduce Script a separate file or is it embedded in the User Event script? I think I can get the Map Reduce to work if I know how to call it from the User Event. I appreciate any input with this question. Thank you!