Jira Code: TM-193
Description
- Whenever a proposal is created for the customer, the customer Lead status will be changed from PROSPECT-Pre sales order to CUSTOMER-Closed Won as a default NetSuite action. This action needs to be changed. When a proposal is created, the customer status needs to remain the same as PROSPECT-Pre sales order.
- When Pre-sales order button is visible at that time the status should not be changed.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* TM-193 UE Restrict customer status change
* **************************************************************************
*
* Date: 11-05-2019
*
* Author: Jobin & Jismi IT Services LLP
*
*****************************************************************************
**/
define(['N/format', 'N/url', 'N/search', 'N/runtime', 'N/record', 'N/https', 'N/ui/serverWidget'],
function(format, url, search, runtime, record, https, serverWidget) {
var main = {
beforeLoad: function(scriptContext) {
log.debug("scriptContext", scriptContext)
var newRecId = scriptContext.newRecord.id;
if (scriptContext.type == "view") {
var salesorder = record.load({
type: "salesorder",
id: newRecId,
isDynamic: false
});
var customer = salesorder.getValue({
fieldId: 'entity'
})
var salescustomer = record.load({
type: "customer",
id: customer,
isDynamic: false
});
salescustomer.setValue({
fieldId: 'entitystatus',
value: "18"
});
var salescustomId = salescustomer.save();
log.debug("salescustomId,", salescustomId);
}
}
};
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;
});