Reputation: 65
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.
Upvotes: 2
Views: 6153
Reputation: 65
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.
Thank you!
Upvotes: 2
Reputation: 15447
People do resort to that sort of thing. Other options include:
Upvotes: 2