C# NetSuite WebServices: Get value from custom field in saved search (ItemSearchAdvanced)

你离开我真会死。 提交于 2019-12-02 11:25:24

问题


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.


回答1:


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:


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;
      }
    }
  }
}


来源:https://stackoverflow.com/questions/28467766/c-sharp-netsuite-webservices-get-value-from-custom-field-in-saved-search-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!