How to disable field and sublist using 2.0?

Hi All,

We all are very much aware of disabling fields and sublist using #SuiteScript1.0, in this post I am going to write about disabling fields and sublist using #SuiteScript2.0  .

Module Needed: N/ui/serverWidget
Script Type: User Event
Function Type: beforeLoad
Function Name: As per your need
Script Name: As per your need

*** Field Display Types:
1. DISABLED -- Prevents a user from changing the field
2. ENTRY -- The sublist field appears as a data entry input field (for a select field without a checkbox)

3. HIDDEN -- The field on the form is hidden.
4. INLINE -- The field appears as inline text
5. NORMAL -- The field appears as a normal input field (for non-sublist fields)
6. READONLY -- The field is disabled but it is still selectable and scrollable (for textarea fields)



/**
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */

define(['N/ui/serverWidget'], function(serverWidget) {
function readOnlyFields(params)
{
          try
            {
                var form = params.form;
     
              
                var mBodyField = form.getField({
                    id: 'myBodyField'
                });
     
                var sublistObj = form.getSublist({
                    id: 'mySublist'
                });
                mBodyField.updateDisplayType({
                                displayType : serverWidget.FieldDisplayType.DISABLED
                            });
                var field1 = sublistObj.getField({id: 'sublistField'});
                field1.updateDisplayType({
                                displayType : serverWidget.FieldDisplayType.DISABLED
                            });
            }
           catch(e)
           {
                 // you message in case of error
            }


}
return {
        beforeLoad: readOnlyFields
    };
});

** Please note: you have to provide field ids (for sublist) to make it readonly, updateDisplayType is not allowed on sublist object directly. You can however hide whole sublist if needed using "SublistDisplayType".


Hope this will help you, please let us know if you have any issue with sublist. 

Thanks
Netsuite Guru

Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page

Comments