Skip to main content

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: MGCLatticeAsyncOperationService A 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: MGCLatticeAsyncOperationResponseContract An MGCLatticeAsyncOperationResponseContract with the tracking ID and status, or the refusal.
NameTypeOptionalDescription
_requestMGCLatticeAsyncOperationRequestContractNoThe 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: MGCLatticeAsyncOperationResponseContract The filled response.
NameTypeOptionalDescription
_responseMGCLatticeAsyncOperationResponseContractNoThe response to fill.
_existingMGCLatticeAsyncOperationTrackingNoThe tracking row of the first submission.
_requestMGCLatticeAsyncOperationRequestContractNoThe 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: DataAreaId The payload's LegalEntityId.
NameTypeOptionalDescription
_serviceNamestrNoThe target service name.
_operationNamestrNoThe target operation name.
_payloadstrNoThe 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: RefRecId The batch job id (BatchJob RecId).
NameTypeOptionalDescription
_trackingIdGuidNoThe tracking id of the operation to run.
_serviceNamestrNoThe target service name (for the job caption).
_operationNamestrNoThe 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: MGCLatticeAsyncOperationStatusContract An MGCLatticeAsyncOperationStatusContract with the current operation status and results.
NameTypeOptionalDescription
_requestMGCLatticeAsyncOperationStatusRequestContractNoThe 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: List The error messages; empty when there are none.
NameTypeOptionalDescription
_errorDetailsstrNoThe 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
NameTypeOptionalDescription
_serviceNamestrNoThe service name.
_operationNamestrNoThe 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: boolean True when the current user holds a privilege that grants the operation; otherwise, false.
NameTypeOptionalDescription
_serviceNamestrNoThe service name.
_operationNamestrNoThe 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: boolean True when the user may invoke the operation; false when not, or when no user is given.
NameTypeOptionalDescription
_serviceNamestrNoThe service name (the AxService name, which is also the registry's ServiceName).
_operationNamestrNoThe operation name.
_userIdUserIdYesThe user to check; the current user when omitted.