我正在尝试通过 REST API 创建新的 Acumatica 案例。我试图填充的案例有一个属性。我为这样的案例属性创建了一个 Detail 对象。
然后我尝试使用以下代码填充测试用例。
public async Task CreateTestCase()
{
Case newCase = new Case
{
ClassID = new JsonObject<string> { value = this.DepartmentToClassID["1"] },
DateReported = new JsonObject<DateTime> { value = DateTime.Now },
BusinessAccount = new JsonObject<string> { value = this.UserOrganizationToBusinessAccount["67"] },
LastActivityDate = new JsonObject<DateTime> { value = DateTime.Now },
Owner = new JsonObject<string> { value = this.OwnerToEmployee["43"] },
ClosingDate = new JsonObject<DateTime?> { value = null },
Severity = new JsonObject<string> { value = this.PriorityToSeverity["1"] },
Status = new JsonObject<string> { value = this.Status["1"] },
Subject = new JsonObject<string> { value = "Test Case" },
Attributes = new List<CaseAttribute>
{
new CaseAttribute
{
AttributeID = new JsonObject<string> { value = "Kayako Ticket Number" },
Value = new JsonObject<string> { value = "12345" }
}
}
};
var json = JsonConvert.SerializeObject(newCase);
try
{
var response = await _httpClient.PutAsync("Custom/1.0/Case", new StringContent(json, Encoding.UTF8, "application/json"));
string res = await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return;
}
}
JsonObject 只是添加 Acumatica 所需的 { "value": } 对象。以下是上述代码生成的 JSON 字符串。
{
"ClassID": {
"value": "SUPPORT"
},
"Contact": null,
"DateReported": {
"value": "2017-07-10T00:41:45.045008-07:00"
},
"BusinessAccount": {
"value": "24SEVEN"
},
"LastActivityDate": {
"value": "2017-07-10T00:41:45.045008-07:00"
},
"Owner": {
"value": "JSS"
},
"ClosingDate": {
"value": null
},
"Severity": {
"value": "Medium"
},
"Status": {
"value": "Open"
},
"Subject": {
"value": "Test Case"
},
"Attributes": [{
"AttributeID": {
"value": "Kayako Ticket Number"
},
"Value": {
"value": "12345"
}
}]
}
这与我运行 GET 时的 case 对象匹配。返回的响应是“500 Internal Server Error”,并且有两个错误:
CR 错误:必需属性为空:“Kayako 票号”
Case.Attributes[1].Value: 'Kayako 票号' 不能为空。
当我创建属性时,它是在索引 0 处创建的。错误表明它正在查看索引 1。有没有办法让我根据属性字符串而不是索引号加载属性?有没有可能该属性根本没有被加载?
我还尝试使用 KAYAKONUMB_Attributes 动态字段来加载条目。 GET 成功返回以下内容:
"KayakoTicketNumber": {
"value": "12002"
},
但是,PUT 返回了上面的第一个错误,但没有返回第二个错误。我的 JSON 字符串与 GET 响应匹配。
更新
按照 Serg 的建议,我扩展了默认端点,现在我可以加载我拥有的三个属性中的两个。我尝试加载的最后一个属性是组合框。似乎需要有一种不同的方式来加载该特定属性。
这是我当前的端点设置:
这是我的新对象初始值设定项:
Case newCase = new Case
{
ClassID = new JsonObject<string> { value = this.DepartmentToClassID["3"] },
Contact = new JsonObject<int> { value = 22322 },
DateReported = new JsonObject<DateTime> { value = DateTime.Now },
BusinessAccount = new JsonObject<string> { value = this.UserOrganizationToBusinessAccount["218"] },
LastActivityDate = new JsonObject<DateTime> { value = DateTime.Now },
Owner = new JsonObject<string> { value = this.OwnerToEmployee["43"] },
ClosingDate = new JsonObject<DateTime?> { value = null },
Severity = new JsonObject<string> { value = this.PriorityToSeverity["1"] },
Status = new JsonObject<string> { value = this.Status["1"] },
Subject = new JsonObject<string> { value = "Test Case" },
Attributes = new List<CaseAttribute<string>>
{
new CaseAttribute<string>
{
AttributeID = new JsonObject<string> { value = "Kayako Ticket Number" },
Value = new JsonObject<string> { value = "12345" }
},
new CaseAttribute<string>
{
AttributeID = new JsonObject<string> { value = "Case Reply Due Date" },
Value = new JsonObject<string> { value = "2010-10-30 00:00:00.000" }
},
new CaseAttribute<string>
{
AttributeID = new JsonObject<string> { value = "Upgrade Stage" },
Value = new JsonObject<string> { value = "7. Test In Progress"}
}
}
};
返回的错误消息是:
PX.Data.PXException:CR 错误:所需属性为空:“升级阶段”
任何帮助将不胜感激,谢谢。
最佳答案
我能够通过创建链接对象并以这种方式设置属性来解决该问题。这是端点设置(抱歉链接的图像,我的代表仍然太低):
这是创建案例对象的代码。我可能需要调整端点和对象,因为当前它链接到属性数组但仅返回第一个属性。我希望有一种方法可以返回各个属性。
Case newCase = new Case
{
ClassID = new JsonObject<string> { value = this.DepartmentToClassID["1"] },
Contact = new JsonObject<int> { value = 22322 },
DateReported = new JsonObject<DateTime> { value = DateTime.Now },
BusinessAccount = new JsonObject<string> { value = this.UserOrganizationToBusinessAccount["218"] },
LastActivityDate = new JsonObject<DateTime> { value = DateTime.Now },
Owner = new JsonObject<string> { value = this.OwnerToEmployee["43"] },
ClosingDate = new JsonObject<DateTime?> { value = null },
Severity = new JsonObject<string> { value = this.PriorityToSeverity["1"] },
Status = new JsonObject<string> { value = this.Status["1"] },
Subject = new JsonObject<string> { value = "Test Case" },
KayakoTicket = new CaseAttribute
{
AttributeID = new JsonObject<string> { value = "Kayako Ticket Number" },
Value = new JsonObject<int> { value = 12345 }
}
};
最后,这是 Acumatica 中的案例截图。
关于json - Acumatica - 通过 Rest API 将必需的属性添加到新案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45006960/