1
votes

I'm using C# MVC to connect to NetSuite using their WebServices API. I have some current code that calls a saved search of inventory items. Here is the current code that is working perfectly:

ItemSearchAdvanced searchItems = new ItemSearchAdvanced();
searchItems.savedSearchId = "128";
SearchResult result = netSuiteSvc.search(searchItems);
int totalRecords = 0;
int processedRecords = 0;

UpdateNetsuitePriceListModel returnObj = new UpdateNetsuitePriceListModel();
returnObj.NewPriceList = new List<NetSuitePriceListRecord>();
if (result.status.isSuccess)
{
    SearchRow[] searchRows = result.searchRowList;
    if (searchRows != null && searchRows.Length >= 1)
    {
        for (int i = 0; i < searchRows.Length - 1; i++)
        {
            ItemSearchRow itemRow = (ItemSearchRow)searchRows[i];
            if (itemRow.basic.itemId != null && itemRow.basic.mpn != null && itemRow.basic.basePrice != null && itemRow.basic.salesDescription != null)
            {
                returnObj.NewPriceList.Add(new NetSuitePriceListRecord()
                {
                    ItemId = itemRow.basic.itemId[0].searchValue,
                    ManufacturerPartNumber = itemRow.basic.mpn[0].searchValue,
                    ContractPrice = Convert.ToDecimal(itemRow.basic.basePrice[0].searchValue),
                    Cost = CalculateProductCostForIngram(Convert.ToDecimal(itemRow.basic.basePrice[0].searchValue)),
                    Description = itemRow.basic.salesDescription[0].searchValue
                });
                processedRecords++;
            }
            totalRecords++;
        }
    }
    else
    {
        throw new Exception("NetSuite Part List Blank");
    }
}
else
{
    throw new Exception("NetSuite Part List Search Failure");
}

Now I have need to pull the itemId from a custom added field rather than the default itemId field.

Obviously since this is a custom field it isn't a property of ItemSearchRowBasic. It looks like instead of the property I can choose "customFieldList" which is an array of "SearchColumnCustomField". If I choose an index for the array I can see that SearchColumnCustomField contains:

  • customLabel
  • internalId
  • scriptId

I imagine I should be able to get the internalId of the SearchColumnCustomField and somehow use that to get the search value for that custom column but I've had some trouble finding any examples that fit so far.

This custom field is a free form text field added to all inventory items.

2

2 Answers

2
votes

Try setting scriptId with the ID of the field ("custitem_xyz"). That should work.

Before 2013 one would use internalId, but since then it changed to scriptId.

2
votes

You would need to loop over the CustomRecord items in the customFieldList. I then usually check for a specific type so I can cast to the correct object, but with some reflection you could probably avoid that.

foreach (Record r in mySearchResponse.recordList){
  foreach (CustomFieldRef cr in ((CustomRecord)r).customFieldList){
    if (cr.GetType().Name == "SelectCustomFieldRef"){
      if (((SelectCustomFieldRef)cr).scriptId == "my_custom_field"){
        internalID = ((CustomRecord)r).internalId;
      }
    }
  }
}