简体   繁体   English

C#NetSuite WebServices:从保存的搜索中的自定义字段中获取值(ItemSearchAdvanced)

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

I'm using C# MVC to connect to NetSuite using their WebServices API. 我正在使用C#MVC通过其WebServices API连接到NetSuite。 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. 现在,我需要从自定义添加的字段而不是默认的itemId字段中提取itemId。

Obviously since this is a custom field it isn't a property of ItemSearchRowBasic. 显然,由于这是一个自定义字段,因此它不是ItemSearchRowBasic的属性。 It looks like instead of the property I can choose "customFieldList" which is an array of "SearchColumnCustomField". 看起来我可以选择“ customFieldList”而不是属性,该属性是“ SearchColumnCustomField”的数组。 If I choose an index for the array I can see that SearchColumnCustomField contains: 如果为数组选择索引,则可以看到SearchColumnCustomField包含:

  • customLabel customLabel
  • internalId internalId
  • scriptId 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. 我想我应该能够获取SearchColumnCustomField的internalId并以某种方式使用它来获取该自定义列的搜索值,但是到目前为止,找到任何适合的示例都有些麻烦。

This custom field is a free form text field added to all inventory items. 此自定义字段是添加到所有库存项目的自由格式文本字段。

Try setting scriptId with the ID of the field ("custitem_xyz"). 尝试使用字段ID(“ custitem_xyz”)设置scriptId。 That should work. 那应该工作。

Before 2013 one would use internalId, but since then it changed to scriptId. 在2013年之前,人们会使用internalId,但是从那以后就更改为scriptId。

You would need to loop over the CustomRecord items in the customFieldList. 您将需要遍历customFieldList中的CustomRecord项目。 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;
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM