MGCLatticeAsyncOperationService
Cross-cutting infrastructure service for submitting long-running operations to the D365 batch framework and polling for their completion status via tracking identifiers. A submission is idempotent on its RequestId.
Methods
new
Initializes a new instance of the MGCLatticeAsyncOperationService class.
- Visibility:
public - Returns:
void
No parameters.
construct
Creates a new instance of the MGCLatticeAsyncOperationService class.
- Visibility:
public - Returns:
MGCLatticeAsyncOperationServiceA new MGCLatticeAsyncOperationService instance.
No parameters.
submitAsyncOperation
Validates the async request, then creates the tracking record and schedules its batch job via MGCLatticeAsyncOperationProcessor in ONE transaction, and returns a tracking ID for the caller to poll. A submission reported as failed therefore leaves nothing behind that could still run: either both the Queued tracking row and its batch job commit, or neither does. The submission's RequestId is required and is the idempotency key of the submission (unique on the tracking table): a repeated submission with the same RequestId for the same service operation returns the first submission's tracking id and current status instead of queueing the work twice; the same RequestId for another operation is refused as DuplicateRequest. The payload must be readable as the operation's request contract and carry its own RequestId (the idempotency key of the posting itself) and an existing LegalEntityId, so work that is certain to fail is refused now instead of being queued.
- Visibility:
public - Returns:
MGCLatticeAsyncOperationResponseContractAn MGCLatticeAsyncOperationResponseContract with the tracking ID and status, or the refusal.
| Name | Type | Optional | Description |
|---|---|---|---|
_request | MGCLatticeAsyncOperationRequestContract | No | The async operation request containing service name, operation name, and serialized request payload. |
buildExistingSubmissionResponse
Answers a repeated submission: the RequestId was already used. For the same service operation the first submission's tracking id and current status are returned (nothing is queued again); for another operation the submission is refused as DuplicateRequest.
- Visibility:
protected - Returns:
MGCLatticeAsyncOperationResponseContractThe filled response.
| Name | Type | Optional | Description |
|---|---|---|---|
_response | MGCLatticeAsyncOperationResponseContract | No | The response to fill. |
_existing | MGCLatticeAsyncOperationTracking | No | The tracking row of the first submission. |
_request | MGCLatticeAsyncOperationRequestContract | No | The repeated request. |
validatePayload
Checks that a payload can run: it must be readable as the operation's request contract and carry the RequestId (the posting's idempotency key) and an existing LegalEntityId, which the target operation requires. Throws a ValidationFailed-classified error otherwise.
- Visibility:
protected - Returns:
DataAreaIdThe payload's LegalEntityId.
| Name | Type | Optional | Description |
|---|---|---|---|
_serviceName | str | No | The target service name. |
_operationName | str | No | The target operation name. |
_payload | str | No | The serialized request payload. |
scheduleProcessorJob
Schedules the runtime batch job that runs one queued async operation and returns its batch job id. Called inside the submit transaction, so the job only becomes visible to the batch server when the tracking row does. The job is a runtime job (Microsoft's pattern for one-off work): it moves to the batch history when it ends and is removed by the batch history cleanup instead of staying in the batch job list.
- Visibility:
protected - Returns:
RefRecIdThe batch job id (BatchJob RecId).
| Name | Type | Optional | Description |
|---|---|---|---|
_trackingId | Guid | No | The tracking id of the operation to run. |
_serviceName | str | No | The target service name (for the job caption). |
_operationName | str | No | The target operation name (for the job caption). |
getAsyncOperationStatus
Looks up the current status of an async operation by the tracking ID that submitAsyncOperation returned. Success is the outcome of the query: true when the operation was found. A malformed request answers Success = false, Status = None, ErrorCode = ValidationFailed; an unknown tracking id answers Success = false, Status = NotFound, ErrorCode = DocumentNotFound. For a found operation Status is its state and, when it failed, ErrorCode/IsRetryable/Errors carry the failure.
- Visibility:
public - Returns:
MGCLatticeAsyncOperationStatusContractAn MGCLatticeAsyncOperationStatusContract with the current operation status and results.
| Name | Type | Optional | Description |
|---|---|---|---|
_request | MGCLatticeAsyncOperationStatusRequestContract | No | The status request carrying the tracking id. |
splitErrorDetails
Splits the stored error details of a failed operation (its error messages joined with "; ") back into a list.
- Visibility:
public - Returns:
ListThe error messages; empty when there are none.
| Name | Type | Optional | Description |
|---|---|---|---|
_errorDetails | str | No | The stored error details. |
validateAsyncTarget
Validates that the specified service/operation combination is a supported async target: registered and enabled, and that the submitting user may invoke it. A pair an administrator disabled is refused as OperationDisabled, a pair that does not exist as ValidationFailed, and a pair the caller holds no privilege for as AccessDenied. All are thrown errors, which submitAsyncOperation reports as a failed submission without queueing anything.
- Visibility:
protected - Returns:
void
| Name | Type | Optional | Description |
|---|---|---|---|
_serviceName | str | No | The service name. |
_operationName | str | No | The operation name. |
hasTargetAccess
Determines whether the current user may invoke the target service operation. Separate from hasTargetOperationAccess only so a test can stand in for the security check.
- Visibility:
protected - Returns:
booleanTrue when the current user holds a privilege that grants the operation; otherwise, false.
| Name | Type | Optional | Description |
|---|---|---|---|
_serviceName | str | No | The service name. |
_operationName | str | No | The operation name. |
hasTargetOperationAccess
Determines whether a user holds a privilege that grants Invoke on a service operation. This is the check the platform's custom service runtime applies before it invokes an operation through the service endpoint (SecurityRights.hasServiceOperationAccess with the AxService name and the operation name), so async execution requires exactly what a direct call requires. Another user's rights are read with SecurityRights::newUser, the pattern Microsoft's EventSecurity uses to check an alert rule's owner from the alerts batch.
- Visibility:
public - Returns:
booleanTrue when the user may invoke the operation; false when not, or when no user is given.
| Name | Type | Optional | Description |
|---|---|---|---|
_serviceName | str | No | The service name (the AxService name, which is also the registry's ServiceName). |
_operationName | str | No | The operation name. |
_userId | UserId | Yes | The user to check; the current user when omitted. |