Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetSuite SuiteTalk API - Get Inventory Details

I'm using the SuiteTalk (API) service for NetSuite to retrieve a list of Assemblies. I need to load the InventoryDetails fields on the results to view the serial/lot numbers assigned to the items. This is the current code that I'm using, but the results still show those fields to come back as NULL, although I can see the other fields for the AssemblyBuild object. How do I get the inventory details (serials/lot#'s) to return on a transaction search?

public static List<AssemblyBuildResult> Get()
{
     var listAssemblyBuilds = new List<AssemblyBuildResult>();

     var service = Service.Context();

     var ts = new TransactionSearch();
     var tsb = new TransactionSearchBasic();

     var sfType = new SearchEnumMultiSelectField
     {
         @operator = SearchEnumMultiSelectFieldOperator.anyOf,
         operatorSpecified = true,
         searchValue = new string[] { "_assemblyBuild" }
     };

     tsb.type = sfType;
     ts.basic = tsb;
     ts.inventoryDetailJoin = new InventoryDetailSearchBasic();

     // perform the search
     var response = service.search(ts);
     response.pageSizeSpecified = true;

     // Process response
     if (response.status.isSuccess)
     {
         // Process the records returned in the response 
                // Get more records with pagination
                if (response.totalRecords > 0)
                {
                    for (var x = 1; x <= response.totalPages; x++)
                    {
                        var records = response.recordList;

                        foreach (var t in records)
                        {
                            var ab = (AssemblyBuild) t;
                            listAssemblyBuilds.Add(GetAssemblyBuildsResult(ab));
                        }

                        if (response.pageIndex < response.totalPages)
                        {
                            response = service.searchMoreWithId(response.searchId, x + 1);
                        }
                    }
                }
            }

            // Parse and return NetSuite WorkOrder into assembly WorkOrderResult list
            return listAssemblyBuilds;
        }
like image 924
user3220882 Avatar asked Aug 17 '16 18:08

user3220882


People also ask

How do I check my inventory in NetSuite?

You first enable serialized inventory items in your Netsuite account before you can access this record type. Go to Setup > Company > Enable Features. On the Items & Inventory tab, under inventory Select the Serialized inventory Check box.

What is inventory Details NetSuite?

The inventory detail subrecord is available when the Advanced Bin / Numbered Inventory Management feature is enabled. This type of record stores values relating to bin numbers and/or serial/lot numbers for items, including line items on transactions.

Does NetSuite have a REST API?

NetSuite's REST API support expands CRUD (Create, Read, Update, and Delete) functionalities across multiple record types. This means that this update has multiple ways to improve the efficiency and interconnectivity of your business's tech stack.

What is NetSuite SuiteTalk?

SuiteTalk is a Web services integration tool for integrating third-party systems with NetSuite. It is also used to build website-to-NetSuite integrations or create custom mobile applications. A Web service provides access to data and functionality through an API across the internet.


1 Answers

After much pain and suffering, I was able to solve this problem with the following code:

    /// <summary>
    /// Returns List of AssemblyBuilds from NetSuite
    /// </summary>
    /// <returns></returns>
    public static List<AssemblyBuildResult> Get(string id = "", bool getDetails = false)
    {
        // Object to populate and return results
        var listAssemblyBuilds = new List<AssemblyBuildResult>();

        // Initiate Service and SavedSearch (TransactionSearchAdvanced)
        var service = Service.Context();
        var tsa = new TransactionSearchAdvanced
        {
            savedSearchScriptId = "customsearch_web_assemblysearchmainlist"
        };

        // Filter by ID if specified
        if (id != "")
        {
            tsa.criteria = new TransactionSearch()
            {
                basic = new TransactionSearchBasic()
                {
                    internalId = new SearchMultiSelectField
                    {
                        @operator = SearchMultiSelectFieldOperator.anyOf,
                        operatorSpecified = true,
                        searchValue = new[] {
                        new RecordRef() {
                            type = RecordType.assemblyBuild,
                            typeSpecified = true,
                            internalId = id
                        }
                    }
                    }
                }
            };

        }

        // Construct custom columns to return
        var tsr = new TransactionSearchRow();
        var tsrb = new TransactionSearchRowBasic();

        var orderIdCols = new SearchColumnSelectField[1];
        var orderIdCol = new SearchColumnSelectField();
        orderIdCols[0] = orderIdCol;
        tsrb.internalId = orderIdCols;

        var tranDateCols = new SearchColumnDateField[1];
        var tranDateCol = new SearchColumnDateField();
        tranDateCols[0] = tranDateCol;
        tsrb.tranDate = tranDateCols;

        var serialNumberCols = new SearchColumnStringField[1];
        var serialNumberCol = new SearchColumnStringField();
        serialNumberCols[0] = serialNumberCol;
        tsrb.serialNumbers = serialNumberCols;

        // Perform the Search
        tsr.basic = tsrb;
        tsa.columns = tsr;
        var response = service.search(tsa);

        // Process response
        if (response.status.isSuccess)
        {
            var searchRows = response.searchRowList;
            if (searchRows != null && searchRows.Length >= 1)
            {
                foreach (SearchRow t in searchRows)
                {
                    var transactionRow = (TransactionSearchRow)t;
                    listAssemblyBuilds.Add(GetAssemblyBuildsResult(transactionRow, getDetails));
                }
            }
        }

        // Parse and return NetSuite WorkOrder into assembly WorkOrderResult list
         return listAssemblyBuilds;
    }

    private static string GetAssemblyBuildLotNumbers(string id)
    {
        var service = Service.Context();
        var serialNumbers = "";

        var tsa = new TransactionSearchAdvanced
        {
            savedSearchScriptId = "customsearch_web_assemblysearchlineitems"
        };

        service.searchPreferences = new SearchPreferences { bodyFieldsOnly = false };
        tsa.criteria = new TransactionSearch()
        {
            basic = new TransactionSearchBasic()
            {
                internalId = new SearchMultiSelectField
                {
                    @operator = SearchMultiSelectFieldOperator.anyOf,
                    operatorSpecified = true,
                    searchValue = new[] {
                        new RecordRef() {
                            type = RecordType.assemblyBuild,
                            typeSpecified = true,
                            internalId = id
                        }
                    }
                }
            }
        };

        // Construct custom columns to return
        var tsr = new TransactionSearchRow();
        var tsrb = new TransactionSearchRowBasic();

        var orderIdCols = new SearchColumnSelectField[1];
        var orderIdCol = new SearchColumnSelectField();
        orderIdCols[0] = orderIdCol;
        tsrb.internalId = orderIdCols;

        var serialNumberCols = new SearchColumnStringField[1];
        var serialNumberCol = new SearchColumnStringField();
        serialNumberCols[0] = serialNumberCol;
        tsrb.serialNumbers = serialNumberCols;

        tsr.basic = tsrb;
        tsa.columns = tsr;

        var response = service.search(tsa);

        if (response.status.isSuccess)
        {
            var searchRows = response.searchRowList;
            if (searchRows != null && searchRows.Length >= 1)
            {
                foreach (SearchRow t in searchRows)
                {
                    var transactionRow = (TransactionSearchRow)t;
                    if (transactionRow.basic.serialNumbers != null)
                    {
                        return transactionRow.basic.serialNumbers[0].searchValue;
                    }
                }
            }
        }

        return serialNumbers;
    }

    private static AssemblyBuildResult GetAssemblyBuildsResult(TransactionSearchRow tsr, bool getDetails)
    {
        if (tsr != null)
        {
            var assemblyInfo = new AssemblyBuildResult
            {
                NetSuiteId = tsr.basic.internalId[0].searchValue.internalId,
                ManufacturedDate = tsr.basic.tranDate[0].searchValue,
                SerialNumbers = tsr.basic.serialNumbers[0].searchValue

            };

            // If selected, this will do additional NetSuite queries to get detailed data (slower)
            if (getDetails)
            {
                // Look up Lot Number
                assemblyInfo.LotNumber = GetAssemblyBuildLotNumbers(tsr.basic.internalId[0].searchValue.internalId);
            }

            return assemblyInfo;
        }

        return null;

    }

What I learned about pulling data from NetSuite:

  • Using SavedSearches is the best method to pull data that doesn't automatically come through in the API objects
  • It is barely supported
  • Don't specify an ID on the SavedSearch, specify a criteria in the TransactionSearch to get one record
  • You will need to specify which columns to actually pull down. NetSuite doesn't just send you the data from a SavedSearch automatically

  • You cannot view data in a SavedSearch that contains a Grouping

  • In the Saved Search, use the Criteria Main Line = true/false to read data from the main record (top of UI screen), and line items (bottom of screen)
like image 185
user3220882 Avatar answered Oct 13 '22 13:10

user3220882