Acumatica - 通过 Rest API 向新案例添加必需属性
Acumatica - Add Required Attribute to new Case through Rest API
我正在尝试通过 REST 创建新的 Acumatica 案例 API。我要填充的案例有一个属性。我为这样的案例属性创建了一个 Detail 对象。
Case Attributes
然后我尝试使用以下代码填充测试用例。
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 时的案例对象匹配。返回的响应是“500 Internal Server Error”并且有两个错误:
CR Error: There are empty required attributes: 'Kayako Ticket Number'
Case.Attributes[1].Value: 'Kayako Ticket Number' cannot be empty.
当我创建属性时,它是在索引 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 Error: There are empty required attributes: 'Upgrade Stage'
非常感谢任何帮助,谢谢。
不幸的是,属性是特例(总是)。据我所知,您已经为此映射了自己的 CaseAttribute
对象 - 不幸的是,如果没有特殊操作,这将无法工作。尝试使用来自 Acumatica 的 Default
端点的 AttributeValue
实体(当然,请确保您的端点扩展 Default
), 可能 对您有帮助。
我能够通过创建链接对象并以此方式设置属性来解决问题。这是端点设置(抱歉链接图片,我的代表仍然太低):
Linked Entity
下面是创建案例对象的代码。我可能需要调整端点和对象,因为它目前正在链接到一组属性,但 return 只链接到第一个。我希望有一种方法可以 return 个人属性。
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中案例的截图。
Created Case
我正在尝试通过 REST 创建新的 Acumatica 案例 API。我要填充的案例有一个属性。我为这样的案例属性创建了一个 Detail 对象。
Case Attributes
然后我尝试使用以下代码填充测试用例。
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 时的案例对象匹配。返回的响应是“500 Internal Server Error”并且有两个错误:
CR Error: There are empty required attributes: 'Kayako Ticket Number'
Case.Attributes[1].Value: 'Kayako Ticket Number' cannot be empty.
当我创建属性时,它是在索引 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 Error: There are empty required attributes: 'Upgrade Stage'
非常感谢任何帮助,谢谢。
不幸的是,属性是特例(总是)。据我所知,您已经为此映射了自己的 CaseAttribute
对象 - 不幸的是,如果没有特殊操作,这将无法工作。尝试使用来自 Acumatica 的 Default
端点的 AttributeValue
实体(当然,请确保您的端点扩展 Default
), 可能 对您有帮助。
我能够通过创建链接对象并以此方式设置属性来解决问题。这是端点设置(抱歉链接图片,我的代表仍然太低):
Linked Entity
下面是创建案例对象的代码。我可能需要调整端点和对象,因为它目前正在链接到一组属性,但 return 只链接到第一个。我希望有一种方法可以 return 个人属性。
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中案例的截图。
Created Case