Jira Code: AHD-105
To use the service items in both purchase order and sales order, we need to create change the service items to resale.
/**
* @NApiVersion 2.x
* @NScriptType MapReduceScript
* @NModuleScope SameAccount
*/
/**
* Script Description
* This Map Reduce to change Service Item Sale to Resale
*
/*******************************************************************************
*
* AHD-105 MR Sale to Resale
*
* *******************************************************************************
*
* $Author: Jobin & Jismi IT Services LLP $
*
* Date: 07 - 06 - 2019
*
* DESCRIPTION
*
*
******************************************************************************/
define(['N/record', 'N/file', 'N/email', 'N/runtime', 'N/search', 'N/email', 'N/encode', 'N/task', 'N/https'],
function (record, file, email, runtime, search, email, encode, task, https) {
var main = {
/*Get inputData for Processing */
getInputData: function () {
var servicesaleitemSearchObj = search.create({
type: "servicesaleitem",
filters:
[
["type","anyof","Service"],
"AND",
["subtype","anyof","Sale"]
],
columns:
[
search.createColumn({
name: "itemid",
sort: search.Sort.ASC,
label: "Name"
})
]
});
return servicesaleitemSearchObj;
},
/*Reduce Function of map Reduce */
reduce: function (context) {
log.debug("context", context)
var objRecord = record.load({
type: record.Type.SERVICE_ITEM,
id: context.key,
isDynamic: true,
});
objRecord.setValue({
fieldId: 'subtype',
value: 'Resale',
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'expenseaccount',
value: 493,
ignoreFieldChange: true
});
objRecord.setValue({
fieldId: 'isfulfillable',
value: true,
ignoreFieldChange: true
});
objRecord.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
},
summarize: function (context) {
log.debug("context", context);
},
}
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
return function () {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.debug("e in " + key, e);
}
}
};
return main;
});