【问题标题】:How do I search for NetSuite inventory items using a custom field?如何使用自定义字段搜索 NetSuite 库存项目?
【发布时间】:2020-08-15 15:46:51
【问题描述】:

使用 NetSuite 2020.1 网络服务,我想通过名称和目录代码(自定义字段)搜索库存项目。

这是我试图通过代码复制的搜索行为的屏幕截图:

这就是我在代码方面的表现(C#):

private string Exists(MapInvItem mapInvItem, ref InventoryItem inventoryItem)
    {
        string sRetrunValue = ITEM_NOTFOUND;

        ItemSearch invSearch = new ItemSearch();           

        SearchCustomField[] searchCustomFields = new SearchCustomField[]
        {
            new SearchStringCustomField()
            {
                @operator = SearchStringFieldOperator.@is,
                operatorSpecified = true,
                searchValue = mapInvItem.catalogcode,
                scriptId = CATALOG_CODE_NSID
            }
        };

        SearchStringField name = new SearchStringField();
        name.@operator = SearchStringFieldOperator.@is;
        name.operatorSpecified = true;
        name.searchValue = mapInvItem.sku;

        ItemSearchBasic invBasic = new ItemSearchBasic();
        invBasic.displayName = name;
        invBasic.customFieldList = searchCustomFields;            

        invSearch.basic = invBasic;

        SearchResult result = Client.Service.search(invSearch);

        if (result.status.isSuccess)
        {
            if (result.totalRecords == 1)
            {
                // one item found => good to go
                Record[] records = result.recordList;
                inventoryItem = (InventoryItem)records[0];
                sRetrunValue = inventoryItem.internalId;
            }
            else if (result.totalRecords > 1)
            {
                // more than one item, we may have a problem
                Record[] records;
                List<InventoryItem> inventoryItems = new List<InventoryItem>();
                // Loop thru page count
                for (int lpc = 0; lpc <= result.totalPages - 1; lpc++)
                {
                    records = result.recordList;
                    for (int lcv = 0; lcv <= records.Length - 1; lcv++)
                    {
                        inventoryItems.Add((InventoryItem)records[lcv]);
                        return ((InventoryItem)records[lcv]).internalId;
                    }
                }
            }
        }
        else
        {
            // log failure
        }

        return sRetrunValue;
    }

注意,对于 result.status.isSuccess,我得到 true,但 totalRecords

【问题讨论】:

    标签: c# netsuite suitetalk


    【解决方案1】:

    使用 itemId 代替 displayName invBasic.itemId = name;

    【讨论】:

    • 甜蜜!就是这样!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多