Phillip
11/03/2020, 9:17 PMrustyshackles
11/03/2020, 9:26 PMPhillip
11/03/2020, 9:29 PMbattk
11/03/2020, 9:50 PMbattk
11/03/2020, 9:50 PMPhillip
11/03/2020, 9:50 PMbattk
11/03/2020, 9:51 PMbattk
11/03/2020, 9:52 PMPhillip
11/03/2020, 9:53 PMPhillip
11/03/2020, 9:54 PMbattk
11/03/2020, 9:55 PMPhillip
11/03/2020, 9:56 PMbattk
11/03/2020, 9:56 PMvar idnew = InvItem.save({enableSourcing: true,
ignoreMandatoryFields: true
});
battk
11/03/2020, 9:56 PMPhillip
11/03/2020, 9:57 PMPhillip
11/03/2020, 9:57 PMbattk
11/03/2020, 9:58 PMstalbert
11/03/2020, 9:58 PMEra
11/03/2020, 9:59 PMEra
11/03/2020, 9:59 PMvar rec = record.create({
type: record.Type.NON_INVENTORY_ITEM,
isDynamic: true
})
rec.setValue({
fieldId: 'subtype',
value: 'Resale'
})
rec.setValue({
fieldId: 'itemid',
value: 'Script - Non Inventory Item for Resale'
})
rec.setValue({
fieldId: 'cost',
value: '1.0'
})
rec.selectLine({
sublistId: 'price1',
line: 0
})
rec.setCurrentSublistValue({
sublistId: 'price1',
fieldId: 'currency',
value: 1
})
rec.setCurrentSublistValue({
sublistId: 'price1',
fieldId: 'price_1_',
value: '1.0'
})
rec.commitLine({
sublistId:'price1'
})
var id = rec.save()
Phillip
11/03/2020, 10:03 PMbattk
11/03/2020, 10:06 PMPhillip
11/03/2020, 10:07 PMbattk
11/03/2020, 10:07 PMbattk
11/03/2020, 10:07 PMPhillip
11/03/2020, 10:09 PMbattk
11/03/2020, 10:09 PMbattk
11/03/2020, 10:11 PMbattk
11/03/2020, 10:12 PMEra
11/03/2020, 10:12 PMEra
11/03/2020, 10:13 PMbattk
11/03/2020, 10:13 PMEra
11/03/2020, 10:14 PMPhillip
11/03/2020, 10:16 PMEra
11/03/2020, 10:18 PMPhillip
11/03/2020, 10:19 PMEra
11/03/2020, 10:22 PMPhillip
11/03/2020, 10:23 PMPhillip
11/03/2020, 10:23 PMbattk
11/03/2020, 10:23 PMEra
11/03/2020, 10:23 PMEra
11/03/2020, 10:23 PMPhillip
11/03/2020, 10:23 PMPhillip
11/03/2020, 10:33 PMPhillip
11/03/2020, 10:48 PMEra
11/03/2020, 10:54 PMPhillip
11/03/2020, 10:55 PMEra
11/03/2020, 10:55 PMEra
11/03/2020, 10:55 PMPhillip
11/03/2020, 10:56 PMEra
11/03/2020, 10:56 PMEra
11/03/2020, 10:56 PMPhillip
11/03/2020, 10:57 PMEra
11/03/2020, 11:01 PMEra
11/03/2020, 11:01 PMPhillip
11/03/2020, 11:04 PMEra
11/03/2020, 11:04 PMEra
11/03/2020, 11:05 PMEra
11/03/2020, 11:06 PMintNewRecId = rec.save({enableSourcing: false, ignoreMandatoryFields: true});
Phillip
11/03/2020, 11:09 PMEra
11/03/2020, 11:11 PMEra
11/03/2020, 11:11 PMEra
11/03/2020, 11:11 PM/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([
'N/record',
'N/error',
'N/log',
'N/runtime',
'N/email'
],
/**
* @param {record} record
* @param {error} error
* @param {log} log
* @param {runtime} runtime
* @param {email} email
*/
function(record, error, log, runtime, email) {
// GLOBAL variables
var DEBUG = true;
var currentScript = runtime.getCurrentScript();
var stExecutionContext = runtime.executionContext; // runtime.ContextType.USER_INTERFACE = 'USERINTERFACE'
var objCurrentUser = runtime.getCurrentUser();
var stAuthor = objCurrentUser.id;//currentScript.getParameter('custscript_email_author_ue');
/**
* <code>afterSubmit</code> event handler. See
* [NetSuite Help: afterSubmit(scriptContext)]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992281.html>}
* for details.
*
* @governance XXX
*
* @param context
* {Object}
*
* @param context.newRecord
* {record} The new record being submitted. See
* [NetSuite Help: record.Record]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4205869719.html>}
* @param context.oldRecord
* {record} The old record before it was modified. See
* [NetSuite Help: record.Record]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4205869719.html>}
* @param context.type
* {UserEventType} The action type that triggered this event. See
* [NetSuite Help: context.UserEventType]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992596.html>}
*
* @return {void}
*
* @static
* @function afterSubmit
*
* @see [NetSuite Help: afterSubmit(scriptContext)]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992281.html>}
* @see [NetSuite Help: context.UserEventType]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992596.html>}
* @see [NetSuite Help: record.Record]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4205869719.html>}
*/
function afterSubmit(scriptContext) /// !!! DOES NOT EXECUTE WHEN SYSTEM GENERATES DROP-SHIP ORDERS !!!
{
var TITLE = 'afterSubmit_transaction'; // function name
try
{
logMessage('DEBUG', TITLE+' #0', '--> Script START <--');
var stExecutionType = scriptContext.type; // scriptContext.UserEventType.CREATE = 'create'
logMessage('DEBUG', TITLE+' #GLOBAL', ' --> stExecutionContext='+stExecutionContext+' | stExecutionType='+stExecutionType
+' | objCurrentUser='+objCurrentUser);
// Script
if ((stExecutionType != scriptContext.UserEventType.DELETE)) // script will not execute on DELETE
{
var objCurrRecord_context = scriptContext.newRecord;
var objOldRecord_context = (stExecutionType != scriptContext.UserEventType.CREATE)?scriptContext.oldRecord:undefined;
var intNewRecId = -1;
var rec = record.create({
type: record.Type.NON_INVENTORY_ITEM,
isDynamic: true
})
rec.setValue({
fieldId: 'subtype',
value: 'Resale'
})
rec.setValue({
fieldId: 'itemid',
value: 'Script - Non Inventory Item for Resale'
})
rec.setValue({
fieldId: 'cost',
value: '1.0'
})
rec.selectLine({
sublistId: 'price1',
line: 0
})
rec.setCurrentSublistValue({
sublistId: 'price1',
fieldId: 'currency',
value: 1
})
rec.setCurrentSublistValue({
sublistId: 'price1',
fieldId: 'price_1_',
value: '1.0'
})
rec.commitLine({
sublistId:'price1'
})
intNewRecId = rec.save({enableSourcing: false, ignoreMandatoryFields: true});
logMessage('DEBUG', TITLE, ' --> intNewRecId='+intNewRecId);
} // script will not execute on DELETE -> scriptContext.UserEventType.DELETE
}
catch (error)
{
logMessage('ERROR', 'Script Error', error.toString());
sendEmailOnError(error.toString(), TITLE, stAuthor);
throw error;
}
}
// END afterSubmit
/******* UTIL - functions ****
******************************
*****************************/
function logMessage(logType, title, details)
{
if(DEBUG)
{
log.debug({
title: logType+' | '+title,
details: details
});
}
if ((logType == 'AUDIT') && (!DEBUG)) {
log.audit({
title: logType+' | '+title,
details: details
});
}
if ((logType == 'ERROR') && (!DEBUG)) {
log.error({
title: logType+' | '+title,
details: details
});
}
}
function sendEmailOnError(errorMsg, TITLE, stAuthor){
if ( errorMsg.length > 0 )
{
var e = error.create(
{
name: TITLE+'_FAILED',
message: JSON.stringify( errorMsg )
} );
//var recipients = '<mailto:eraceanu@netsuite.com|eraceanu@netsuite.com>';
var subject = 'UserEvent script ' + runtime.getCurrentScript().id + ' failed during execution. ';
var body = 'An error occurred with the following information:\n' + 'Error code: ' + e.name + '\n' + 'Error msg: ' + e.message;
email.send(
{
author: stAuthor,
recipients: stAuthor,
subject: subject,
body: body
} );
}
}
return {
afterSubmit: afterSubmit
};
});
Phillip
11/03/2020, 11:15 PMPhillip
11/03/2020, 11:23 PMbattk
11/04/2020, 11:59 AMbattk
11/04/2020, 11:59 AMEra
11/04/2020, 12:03 PMbattk
11/04/2020, 12:06 PMbattk
11/04/2020, 12:07 PMbattk
11/04/2020, 12:07 PMbattk
11/04/2020, 12:08 PMEra
11/04/2020, 12:09 PMbattk
11/04/2020, 12:10 PMEra
11/04/2020, 12:15 PMEra
11/04/2020, 12:16 PMbattk
11/04/2020, 12:18 PMEra
11/04/2020, 12:22 PMbattk
11/04/2020, 12:29 PMbattk
11/04/2020, 12:29 PMbattk
11/04/2020, 12:30 PMEra
11/04/2020, 12:32 PMbattk
11/04/2020, 12:33 PMEra
11/04/2020, 12:34 PMEra
11/04/2020, 12:34 PMbattk
11/04/2020, 12:37 PMbattk
11/04/2020, 12:37 PMbattk
11/04/2020, 12:37 PMbattk
11/04/2020, 12:38 PM