Hello all,
Our opportunity records frequently have more than one sales order created from them. We use a custom status when they are open (Valid) but after a sales order is created from the opportunity record, native NetSuite closes the opportunity record.
Currently, I'm manually reopening the opportunity records so our sales team can create more sales orders from the same opportunity. We tried the script listed below running after submit, and it changes the status back to Valid but then immediately marks it as closed again.
Other than updating it nightly via scheduled workflow, I'm stuck. Any help is greatly appreciated. Thanks!
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/search'], function(record, search) {
function afterSubmit(context) {
if (context.type !== context.UserEventType.CREATE) {
// only execute the script when a new sales order is created
log.debug('New Sales Order NOT created');
return;
}
var newRecord = context.newRecord;
var opportunityId = newRecord.getValue({
fieldId: 'opportunity'
});
if (!opportunityId) {
// sales order does not have an opportunity linked to it
log.debug('No Opportunity ID');
return;
}
var opportunity = record.load({
type: record.Type.OPPORTUNITY,
id: opportunityId
});
log.debug('Opportunity ID', opportunityId);
opportunity.setValue({
fieldId: 'entitystatus',
value: '33'
});
var test = opportunity.getValue('entitystatus');
log.debug('Opp Status', test);
opportunity.save();
}
return {
afterSubmit: afterSubmit
};
});