define(['N/record', 'N/log', 'N/runtime'],
/**
* @param{record} record
* @param{log} log
*/
(record, log, runtime) => {
/**
* Defines the function definition that is executed before record is loaded.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @param {Form} scriptContext.form - Current form
* @param {ServletRequest} scriptContext.request - HTTP request information sent from the browser for a client action only.
* @since 2015.2
*/
const beforeLoad = (scriptContext) => {
let recCurrent = scriptContext.newRecord;
let role = recCurrent.getValue({
fieldId: 'nlrole'
});
let userId = runtime.getCurrentUser().id;
if (scriptContext.type === 'copy' && ((role != 3) || (role == 3 && (userId != 55873 || userId != 55872)))) {
throw new Error('Make a copy of inventory item is not allowed.');
}
}
return {
beforeLoad: beforeLoad
}
});