【问题标题】:How do we retrieve values of Custom Lists(dropdown) in Netsuite我们如何在 Netsuite 中检索自定义列表(下拉)的值
【发布时间】:2016-08-03 19:25:27
【问题描述】:

我的记录类型为“XYZ”,其中包含名为“奖励区域”的字段,其类型为列表/记录。 “奖励区”是自定义列表类型,是一个下拉控件。

使用 Suitetalk 我如何从该下拉列表中检索这些值?

谢谢

【问题讨论】:

    标签: web-services netsuite suitetalk


    【解决方案1】:

    我认为像this 这样的东西应该可以工作。它用于将返回的 internalId 的结果转换为实际的文本类型,您也许可以以另一种方式利用它。也许你可以创建一个类似这样的查找列表(C#):

    public Dictionary<string, Dictionary<long, string>> getCustomFieldLists()
    {
        return
            nsService.search(new CustomListSearch())
                .recordList.Select(a => (CustomList) a)
                .ToDictionary(a => a.name,
                    a => a.customValueList.customValue
                         .ToDictionary(b => b.valueId, c => c.value));
    }
    
    var valueLookup = getCustomFieldLists()["award area"];
    

    【讨论】:

      【解决方案2】:

      这是我为自己做的,因为我对 NetSuite 不只是为我们提供访问这些的简单方法感到恼火。我想要以下数据供参考:

      • 自定义列表的内部 ID
      • 自定义列表的名称
      • 自定义列表项的内部 ID
      • 自定义列表项的名称值

      我想要/需要访问所有这些内容,并且我希望能够通过提供自定义列表的内部 ID 和自定义列表项的内部 ID 来获取自定义列表项的名称值。因此,在我自制的集成客户端中,类似于 David Rogers 的回答,但没有所有花哨的 Linq,我发现最好的解决方案是 Dictionary>>。

      这样,对于外部字典,我可以将键设置为自定义列表的内部 ID,而对于内部字典,我可以将键设置为自定义列表项本身的内部 ID。然后,我将“free”的自定义列表的名称作为元组的开头部分,并将“free”的实际名称值作为内部字典的值。

      下面是我生成这个对象的方法代码:

      /// <summary>
      /// Gets the collection of all custom lists, and places it in the public CustomListEntries object
      /// </summary>
      /// <returns></returns>
      private Dictionary<string, Tuple<string, Dictionary<long, string>>> GetCustomLists()
      {
          Dictionary<string, Tuple<string, Dictionary<long, string>>> customListEntries = new Dictionary<string, Tuple<string, Dictionary<long, string>>>();
          SearchPreferences sp = SuiteTalkService.searchPreferences; //Store search preferences to reset back later, just need body fields this one time
          SuiteTalkService.searchPreferences = new SearchPreferences() { bodyFieldsOnly = false };
          SearchResult sr = SuiteTalkService.search(new CustomListSearch());
          SuiteTalkService.searchPreferences = sp; //Restore search preferences
      
          foreach (CustomList cl in sr.recordList)
          {
              Dictionary<long, string> customListItems = new Dictionary<long, string>();
              if (cl.customValueList == null) continue;
              foreach (CustomListCustomValue clcv in cl.customValueList.customValue)
              {
                  customListItems.Add(clcv.valueId, clcv.value);
              }
              customListEntries.Add(cl.internalId, new Tuple<string, Dictionary<long, string>>(cl.name, customListItems));
          }
          return customListEntries;
      }
      

      然后,在我的集成类的构造函数中,我可以将我的对象设置为返回结果:

      public Dictionary<string, Tuple<string, Dictionary<long, string>>> CustomListEntries = GetCustomLists();
      

      最后,每当我需要访问这些值时,由于我提前设置了所有这些,我可以执行以下操作:

      dr[Class] = SuiteTalkIntegrator.CustomListEntries[lorr.typeId].Item2[long.Parse(lorr.internalId)];
      

      在上面的这个例子中,我的“lorr”对象是一个 ListOrRecordRef 对象,它是我从 SavedSearch 的搜索结果中的 SearchColumnSelectCustomField.searchValue 获得的。我不知道这是否适用于找到此代码的其他人,但由于我对找到此问题的简单答案感到沮丧,我想我会与大家分享我的解决方案。

      坦率地说,我最沮丧的是,这个功能不是开箱即用的,但我注意到 NetSuite 在他们的 SuiteTalk API 中做出了很多糟糕的设计选择,比如没有定制记录字段的“RecordField”类,而不是将记录字段放在 RecordField 的 IEnumerable 下,以便程序员可以以通用方式遍历记录中的所有值,而无需显式命名它们并重新构造相同的代码逻辑一遍一遍……呃……

      【讨论】:

        猜你喜欢
        • 2020-04-11
        • 1970-01-01
        • 2016-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-21
        • 1970-01-01
        相关资源
        最近更新 更多