ANS-0752 · WEB SERVICES & INTEGRATIONS

How to Perform an Inventory Item Search Using NetSuite SuiteTalk SOAP API in C#?

Learn to programmatically search for inventory items by keyword and type using the NetSuite SuiteTalk SOAP API with C#.

Short answer

To search for inventory items in NetSuite using C# and SuiteTalk SOAP API, instantiate an ItemSearch object, define SearchStringField for item name and SearchEnumMultiSelectField for item type, then execute the search via _service.search. Iterate through results to display item details.

Scenario

Developers integrating external applications with NetSuite often need to retrieve specific inventory item records. A common requirement is to search for items based on keywords in their name and filter by item type, such as inventory items, to ensure accurate data retrieval for business processes.

Solution

NetSuite developer resources provide C# examples demonstrating how to interact with the SuiteTalk SOAP API. The following C# code illustrates how to perform an inventory item search by name and type, including a helper method to display item fields. This approach leverages objects like ItemSearch, SearchStringField, SearchEnumMultiSelectField, ItemSearchBasic, and the _service.search method to construct the search criteria and execute it.

private String ITEM_TYPE  "_inventoryItem";
          /// <summary> Searches for InventoryItem records based on a
keyword entered by
          /// the user.  All inventory items, including parent items,  with the
          /// keyword found in their name field will be returned.
          /// </summary>

    public virtual void  searchInventoryItemByName()
                    {
    _out.writeLn("Enter a keyword of the item name to be searched");
     System.String keyWordString  _out.readLn();

                    ItemSearch itemSearch  new ItemSearch();

                    SearchStringField name  new SearchStringField();
                    name.@operator  SearchStringFieldOperator.contains;
                    name.operatorSpecified  true;
                    name.searchValue  keyWordString;

                    SearchEnumMultiSelectField type  new
SearchEnumMultiSelectField();
                    String[] inv  new String[1];
                    inv[0]  ITEM_TYPE;
                    type.@operator  SearchEnumMultiSelectFieldOperator.anyOf;
                    type.operatorSpecified  true;
                    type.searchValue  inv;

                    ItemSearchBasic itemBasic  new ItemSearchBasic();
                    itemBasic.type  type;
                    itemBasic.itemId  name;

                    itemSearch.basic  itemBasic;

                    SearchResult res  _service.search(itemSearch);
                    if (res.status.isSuccess)
                    {
                        Record[] recordList;
                        _out.writeLn("

Number of items found with thenkeyword " + keyWordString + ": " + res.totalRecords);
                        if (res.totalRecords > 0)
                        {
                            _out.writeLn("

Page size: " + res.pageSize);

                            for (int i  1; i < res.totalPages; i++)
                            {
                                recordList  res.recordList;
                                _out.writeLn("Page " + res.pageIndex);
                                _out.writeLn("------");

                                for (int j  0; j < recordList.Length; j++)
                                {
                                    if (recordList[j] is InventoryItem)
                                    {
                                        InventoryItem item
(InventoryItem) (recordList[j]);
                                        displayInventoryItemFields(item);
                                    }
                                }
                                if (res.pageIndex < res.totalPages)
                                {
                                    res
_service.searchMoreWithId(res.searchId, i + 1);
                                }
                            }
                        }
                    }
                    else
                    {
                        _out.error(getStatusDetails(res.status));
                    }
                }
/// <summary> A helper method that takes an
InventoryItem and prints out
                /// its Display Name, Item ID and Cost fields.
                /// </summary>
                private void  displayInventoryItemFields(InventoryItem item)
                {
                    if (item ! null)
                    {
                        if (item.displayName ! null)
                        {
                            _out.writeLn("     Display Name:
     " + item.displayName);
                        }
                        else
                        {
                            _out.writeLn("     Display Name:
     none");
             
                        }
                    }
                }

Expert NetSuite Support

Need help with this NetSuite issue?

Web Services & Integrations consulting and configuration support

Talk to a consultant