Requirement
We need to hide some buttons on view mode of the draft invoice on Employee Center Role.
Solution
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/currentRecord', 'N/record', 'N/runtime'],
/**
* @param{currentRecord} currentRecord
* @param{record} record
* @param{runtime} runtime
*/
(currentRecord, record,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) => {
try {
//When the draft invoice is viewed from the employee center, buttons other than print button is hidden
var centerType = runtime.getCurrentUser().roleCenter
if (centerType === 'EMPLOYEE') {
if (scriptContext.type === scriptContext.UserEventType.VIEW) {
//Removing the edit , back, void, wip creation,updatedate,refresh, approve, add wip buttons in view mode in employee centre role.
var form = scriptContext.form;
form.removeButton({
id: 'edit',
});
form.removeButton({
id: 'back',
});
form.removeButton({
id: 'custpage_void',
});
form.removeButton({
id: 'custpage_wipcreation',
});
form.removeButton({
id: 'custpage_gli',
});
form.removeButton({
id: 'custpage_updatedate',
});
form.removeButton({
id: 'custpage_refresh',
});
form.removeButton({
id: 'custpage_approve',
});
form.removeButton({
id: 'custpage_add_wip',
});
}
}
} catch (e) {
log.debug('Error@Before Load',e)
}
}
return {beforeLoad}
});