Cases Sub Service - Nioron07/Easy-Acumatica GitHub Wiki

This page covers the CasesService, which is your primary tool for interacting with Case records in Acumatica.

1. Importing Helpers

Before you start, import the necessary helpers for building case payloads and queries.

from easy_acumatica.models.case_builder import CaseBuilder
from easy_acumatica.models.query_builder import QueryOptions

2. Creating Cases

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 also provide QueryOptions to customize the response, for example, to expand related entities.

Example: Create a new high-priority case

# Build the case payload
case_payload = (
    CaseBuilder()
    .case_class("HIGH")
    .subject("Urgent: Main website is down")
    .description("The main e-commerce site is returning a 503 error for all users.")
    .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']}")

3. Specialized Helper Methods

The CasesService also includes helpers for more specific, common tasks.

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.

Example: Create a new case and link it to a master ticket

# Build the payload for the new case, specifying the existing case to link to.
# The `add_related_case` method in the builder would be responsible for
# constructing the 'RelatedCases' part of the request payload.
related_case_payload = (
    CaseBuilder()
    .case_class("MEDIUM")
    .subject("Users in Texas also reporting website down")
    .description("This appears to be related to the main outage.")
    .add_related_case("CR000456") # The CaseCD of the existing master ticket
)

# Create the new case and link it
linked_case = client.cases.link_case_to_another_case("24.200.001", related_case_payload)

# The response automatically includes the expanded 'RelatedCases' field
print(f"Successfully created case: {linked_case['CaseCD']['value']}")
print(f"Linked to Case: {linked_case['RelatedCases'][0]['value']['RelatedCaseCD']['value']}")