Reputation: 346
I am trying to create new Acumatica cases through the REST API. There is an attribute on the cases that I am trying to populate. I created a Detail object for the case attributes like this.
I then tried to populate a test case using the below code.
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 just adds the { "value": } object that Acumatica requires. Here is the JSON string that results from the above code.
{
"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"
}
}]
}
This matches the case object when I run a GET. The response that comes back is "500 Internal Server Error" and there are two errors:
CR Error: There are empty required attributes: 'Kayako Ticket Number'
Case.Attributes[1].Value: 'Kayako Ticket Number' cannot be empty.
When I create the attribute, it is created at index 0. The error indicates it is looking at index 1. Is there a way for me to load the attribute based on the attribute string and not the index number? Is it possible the attribute is not even being loaded at all?
I also tried using the KAYAKONUMB_Attributes dynamic field to load the entry. The GET successfully returned the following:
"KayakoTicketNumber": {
"value": "12002"
},
The PUT, however, returned the first error above, but not the second one. My JSON string matched the GET response.
Following Serg's advice, I extended the default endpoint, and now I am able to load two of the three attributes I have. The last attribute I am trying to load is a combo box. It seems like there needs to be a different way to load that particular attribute.
Here is my current endpoint setup:
And here is my new object initializer:
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"}
}
}
};
The error message being returned is:
PX.Data.PXException: CR Error: There are empty required attributes: 'Upgrade Stage'
Any help would be greatly appreciated, thank you.
Upvotes: 2
Views: 870
Reputation: 346
I was able to solve the issue by creating a linked object and setting the attribute that way. Here is the endpoint setup (sorry for the linked images, my rep is still too low):
And here is the code for creating the case object. I may need to tweak the endpoint and the objects as currently it is linking to an array of attributes but returning only the first one. I am hoping there is a way to return individual attributes.
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 }
}
};
Finally, here is a screenshot of the case in Acumatica.
Upvotes: 2
Reputation: 5832
Unfortunately, attributes are a special case (always). From what I see, you've mapped your own CaseAttribute
object for this - and, unfortunately, this won't work without special actions. Try using AttributeValue
entity from Acumatica's Default
endpoint (and, of course, make sure that your endpoint extends Default
), that might help you.
Upvotes: 1