Cases Service
The `CasesService` is your primary tool for interacting with Case records in Acumatica. It allows you to programmatically create support cases, link related cases together, and manage their properties.
Importing Helpers
To create cases, you'll need the `CaseBuilder` from the `easy_acumatica.models` module. You may also need `QueryOptions` if you wish to customize the API response.
from easy_acumatica.models.case_builder import CaseBuilder
from easy_acumatica.models.query_builder import QueryOptions
Service Methods
create_case(api_version, builder, options=None)
This is the main method for creating a new case record. You must provide a `CaseBuilder` object containing the new case's details. You can optionally provide `QueryOptions` to customize the response, for example, to expand related entities.
# Build the case payload
case_payload = (
CaseBuilder()
.class_id("HIGH") # Set the Case Class
.subject("Urgent: Main website is down")
.set("BusinessAccount", "ABCCORP") # Set the customer for the case
)
# Create the case
new_case = client.cases.create_case("24.200.001", case_payload)
print(f"Successfully created case with ID: {new_case['CaseCD']['value']}")
link_case_to_another_case(api_version, builder)
This helper method creates a new case and links it to one or more existing cases in a single API call. This is useful for tracking duplicate issues or grouping related problems. To use this method, your `CaseBuilder` must include the `CaseCD` of the case(s) you want to link to, added via the `.add_related_case()` method.
# Build the payload for the new case, specifying the existing case to link to.
related_case_payload = (
CaseBuilder()
.class_id("MEDIUM")
.subject("Users in Texas also reporting website down")
.add_related_case("CR000456") # The CaseCD of the existing master ticket
)
# Create the new case and link it.
# The response automatically includes the expanded 'RelatedCases' field.
linked_case = client.cases.link_case_to_another_case(
"24.200.001",
related_case_payload
)
print(f"Successfully created case: {linked_case['CaseCD']['value']}")