2
votes

On NetSuite Items forms, I would like to remove some items of the dropdown list “Sub-Item Of” (field name "parent"), which currently displays all NetSuite Items.

I've tried to create a User Event Script, on Before Load and use the API nlapiRemoveSelectOption, however NetSuite raises an error informing that the method does not exist. When trying to use the API on Client side, it returns an error informing the method is not available on client. The method was called as following:

nlapiRemoveSelectOption('parent', '1');  // 1 is the internal Id

After investigating the scripts source code, the only way I was able to remove the items from the list was using a non-documented method named deleteOneOption on Client Side.

getDropdown(window.document.getElementsByName('inpt_parent')[0]).deleteOneOption('1');    

However, this should not be the best approach, as it is not documented and I am accessing the DOM objects directly, which may not work on the future versions.

Does anyone know a better way to remove some items from that field?

Thank you.

2

2 Answers

2
votes

People do resort to that sort of thing. Other options include:

  • use filtering on the target field to limit drop-down options
  • if this is for item selection use a custom sublist to manage the items shown
  • if neither of the above work what I've generally done is hide the natural drop-down on the form and add custom drop-down over which I have better control. Then in a Client script I take changes from the custom drop-down and apply those to the hidden field. Two scenarios:
    • if you know the drop-down contents when you load the form you can just create the list as a new select field on the form and populate it in a before load user event script.
    • if you need to react on other things being selected on the form and Netsuite's built-in sourcing doesn't work then you can use a client script to change the drop-down's content based on form events.
2
votes

Thank you for the suggestion, it really helped me out. I ended up with the following approach:

  • Create a User Event script (Before Load event), adding the field programmatically, so that I have more control over the list and I am able to remove or insert options. In the case the API nlapiRemoveSelectOption works.

    function beforeLoad(type, form, request) {
    
        var fld = form.addField('custpage_item', 'select', 'Subitem Of', 'item', null);
    
        // Inserts the field after the "Subitem Of" original
        form.insertField(fld, 'parent'); 
    
        nlapiRemoveSelectOption('custpage_item', '1');  // internal id to remove
    }
    
  • Create a Client Script (Field Changed event) to copy data from the new custom field to the original field. Also, on page init the script sets the value to the added field.

  • Hide the original field on the custom form.

Thank you!