Reputation: 47
I am trying to call pageinit client script from user event beforeload. When I deploy client script on record, it works perfectly that is hides certain tabs. But when I am trying to call it from user event, client script is not executing. Please advice!
define(['N/record', 'N/log', 'N/ui/serverWidget'], function(record, log, ui) {
function beforeLoad(context) {
var type = context.type;
var form = context.form;
log.debug("type",type);
if (type === context.UserEventType.CREATE || type === context.UserEventType.EDIT || type === context.UserEventType.VIEW) {
log.debug("inside type");
//Call client script to hide subtabs for invalid roles
form.clientScriptModulePath = 'SuiteScripts/ABC/SuiteScript 2.1/Client Scripts/cs_hide_bts_elements.js';
}
}
return {
beforeLoad: beforeLoad,
};
});
Upvotes: 0
Views: 37
Reputation: 8847
In bl_hideRestrictedEmployeeFields
, the type
conditions will never be true
because the values of type
are never "view"
or "create"
; thus, you'll never attach the Client Script to the form.
Compare type
to the UserEventType
values, like you did in the beforeLoad
function instead.
Better yet, you are already doing the same comparison in beforeLoad
, so don't duplicate it in bl_hideRestrictedEmployeeFields
. Remove the conditions in bl_hideRestrictedEmployeeFields
, and move the bl_hideRestrictedEmployeeFields
call inside the if
in beforeLoad
.
Additionally, Client Script entry points do not run in VIEW
mode.
Upvotes: 0