我有记录类型“XYZ”,其中有一个名为“奖励区域”的字段,它是列表/记录类型。“奖励区域”是自定义列表类型,是一个下拉控件。
使用 Suitetalk 我如何从该下拉列表中检索这些值?
谢谢
我有记录类型“XYZ”,其中有一个名为“奖励区域”的字段,它是列表/记录类型。“奖励区域”是自定义列表类型,是一个下拉控件。
使用 Suitetalk 我如何从该下拉列表中检索这些值?
谢谢
我认为这样的事情应该有效。它用于将返回的 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"];
以下是我自己的做法,因为 NetSuite 不仅为我们提供了访问这些内容的简单方法,我对此感到恼火。我想要以下数据供参考:
我想要/需要访问所有这些内容,并且我希望能够通过提供自定义列表的内部 ID 和自定义列表项的内部 ID 来获取自定义列表项的名称值。因此,在我自制的集成客户端中,类似于 David Rogers 的回答,但没有所有花哨的 Linq,我发现最好的解决方案是 Dictionary>>。
这样,对于外部字典,我可以将键设置为自定义列表的内部 ID,而对于内部字典,我可以将键设置为自定义列表项本身的内部 ID。然后,我将“免费”的自定义列表的名称作为元组的开头部分,并将“免费”的实际名称值作为内部字典的值。
下面是我生成这个对象的方法代码:
/// <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 下,以便程序员可以以通用方式遍历记录中的所有值,而无需明确命名它们并一遍又一遍地重新构造相同的代码逻辑……呃……