gpt4 book ai didi

acumatica - 从 REST API 获取组合框值集

转载 作者:行者123 更新时间:2023-12-03 08:27:17 26 4
gpt4 key购买 nike

我正在通过 REST API 使用联系人,我正在尝试在我的应用程序中添加一个输入字段以指定 ContactSource。问题在于 Source 字段是一个组合框,这意味着它的值可以通过自动化步骤 (SM205000) 进行修改。例如,下面是 Source 的默认值列表:

enter image description here

对应于该字段的CRMSourcesAttribute

// Token: 0x020003D3 RID: 979
public class CRMSourcesAttribute : PXStringListAttribute
{
// Token: 0x06004052 RID: 16466 RVA: 0x000FD4A4 File Offset: 0x000FB6A4
public CRMSourcesAttribute() : base(new string[]
{
"W",
"H",
"R",
"L",
"O"
}, new string[]
{
"Web",
"Phone Inquiry",
"Referral",
"Purchased List",
"Other"
})
{
}

// Token: 0x04002158 RID: 8536
public const string _WEB = "W";

// Token: 0x04002159 RID: 8537
public const string _PHONE_INQ = "H";

// Token: 0x0400215A RID: 8538
public const string _REFERRAL = "R";

// Token: 0x0400215B RID: 8539
public const string _PURCHASED_LIST = "L";

// Token: 0x0400215C RID: 8540
public const string _OTHER = "O";
}

我应该通过自动化步骤表来获取组合框的最终值,还是有一种方法可以通过指定 DAC.FIELD 的 REST API 获取它?

最佳答案

对于这样的任务,我建议使用反射。下面是使用示例读取属性的示例:

    protected IEnumerable records()
{
//var row = new ClassFilter { ClassName = "PX.Objects.CR.CRMSourcesAttribute" };
var row = Filter.Current;
if (row != null && !string.IsNullOrWhiteSpace(row.ClassName))
{
var type = Type.GetType(row.ClassName) ??
Type.GetType(row.ClassName + ", PX.Objects");

if (type != null)
switch (type.BaseType.Name)
{
case "PXIntListAttribute":
{
int[] values;
string[] labels;
GetRecords(type, out values, out labels);

for (int i = 0; i < values.Length; i++)
yield return new KeyValueRecord { Key = values[i].ToString(), UiValue = labels[i] };
break;
}
case "PXStringListAttribute":
{
string[] values, labels;
GetRecords(type, out values, out labels);

for (int i = 0; i < values.Length; i++)
yield return new KeyValueRecord { Key = values[i], UiValue = labels[i] };
break;
}
}
}
}

private void GetRecords<T>(Type type, out T[] values, out string[] labels)
{
var obj = Activator.CreateInstance(type);
var flags = BindingFlags.NonPublic | BindingFlags.Instance;

values = type.GetField("_AllowedValues", flags).GetValue(obj) as T[];
labels = type.GetField("_AllowedLabels", flags).GetValue(obj) as string[];
}

和图片:

enter image description here

之后,您只需将图形和 DAC 添加到端点并将其公开即可。

带有注释的完整源代码可用 here .

关于acumatica - 从 REST API 获取组合框值集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57529240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com