suitescript 2.0:当我使用 removeSelectOption 时,抛出 'TypeError Cannot read property "removeSelectOption" of null' 错误

suitescript 2.0:When I use removeSelectOption,throw a 'TypeError Cannot read property "removeSelectOption" of null' error

当我使用 removeSelectOption 删除所有下拉菜单时出现 js 错误 list.The 代码如下:

function fieldChanged(scriptContext) {
    if(scriptContext.fieldId == 'class'){
        var currentRecord = scriptContext.currentRecord;
        var brand_id = currentRecord.getValue({fieldId:'class'});
        if(brand_id){
            var itemList = [];
            var itemField = currentRecord.getField({
                fieldId: 'item'
            });
            itemField.removeSelectOption({
                value: null,
            });
            search.create({
                type: search.Type.INVENTORY_ITEM,
                columns:[{name:'internalid'}],
                filters:[
                    ['custitem30',search.Operator.ANYOF,brand_id]
                ]
            }).run().each(function(result){
                item_id = result.getValue({
                    name:'internalid'
                });
                var in_item = record.load({
                    type: record.Type.SALES_ORDER, 
                    id: item_id,
                });
                itemList.push(item_id);
                itemField.insertSelectOption({
                    value: item_id,
                    text: in_item
                });
                console.log('item_id:' + item_id);
            });
            console.log('itemList:' + itemList);
        }
    }
}

帮助中心的api文档说——要从列表中删除所有选项,将此字段设置为空,如下所示:

field.removeSelectOption({
value: null,
});

如果我想从下拉列表中删除所有选项,我应该怎么做? 谢谢

首先你已经得到了字段对象

var field = currentRecord.getField({
    fieldId: 'Your Field ID'
});

然后使用下面的代码

field.removeSelectOption({
value: null,
});

  1. 创建项目保存搜索 2.Transaction 已保存搜索的表单项过滤器字段 select。

关于你的问题,我假设你只在项目字段中显示库存项目。