How to Recall/Cancel a workflow through code in AX 2012

To recall a workflow through code you can use the cancelworkflow method in workflow class. It takes the correlationId and a comment as parameters and gets the job done for you. Example

workflow::cancelworkflow(CorrelationId, “Cancelling this workflow”)

Now you are probably thinking How do I find my workflows CorrelationId. You can do that by querying WorkflowTrackingStatusTable sorting it with time and instance number and joining it with SysWorkflowtable against the correlationId field and in the contextId you pass the RecId of your record for example PO RecId.

2 thoughts on “How to Recall/Cancel a workflow through code in AX 2012

  1. why we have to do joining with the table WorkflowTrackingStatusTable although correlationId can be retrieved directly from SysWorkflowtable using the field WorkflowCorrelationId and by filtering on ContextRecId & ContextTableId?

    Like

Leave a comment