0

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,    
  };
});

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @erictgrubaugh for the response. I tried with simple code also. I can see log, inside type. Still client script does not trgger. I have updated the code. Please suggest if anything wrong.
0

The client script triggered when I added logic outside pageinit function.

function pageinit()
{
}
//Logic to hide subtabs.

Also I noticed that, I uploaded client script in the destination folder in the netsuite file cabinet, but script was not in the customization - scripting- client scripts list page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.