Workflow via Code – Part 5

Bonus – Adding Auto-Run Actions (IsAutoRun)

In the original 4-part series, we looked at how to setup a basic workflow via code. Once I converted all of our workflows from GUI workflows in the Customization Project of Acumatica into coded workflows, I found one sticky point that I had to go back to the GUI to handle. This was the Auto-Run Action feature that allows me to automatically fire another action when entering a state.


In Part 1 of the series, we saw the introduction of a PXAutoAction for InitializeState.

View this gist on GitHub

This PXAutoAction allows (and is required for) defining IsAutoAction when adding the action to the workflow. However, trying to apply the same IsAutoAction to a normal PXAction type action complains because there is no conversion between PXAutoAction and PXAction. In simple terms, it just doesn’t work to try to add an normal action to the workflow and make it IsAutoRun! Even worse, converting the PXAction to a PXAutoAction seems to break the original action.

Defining the Auto-Run Action

An Auto-Run Action is defined in code using IsAutoRun(condition) as shown below.

View this gist on GitHub

The key, however, to adding an Auto-Run Action is to define it first and THEN update it. This seems very counterintuitive since we just defined the action, but Acumatica appears to need to know about the action on a state before it can subsequently auto-run it.

In the approval workflow extension example below, the workflow state is added with Pending Approval, Rejected, and Approved states. The PushInventoryID action is added to the Approve stated. For simplicity of testing the action, it has been duplicated in the toolbar as well.

Subsequently, the flow state is referenced again with .WithFlowStates, but this time for UPDATING the action into an Auto-Run Action. To do this, the Approved state is updated, and then the PushInventoryID action is updated as well. Addition of a => a.IsAutoAction() configures the workflow to fire this action automatically. A condition can be added IsAutoAction(conditions.MyCondition) to control when the action is triggered to run automatically.

Adding IsAutoRun()

Special thanks goes to Evgeny Afanasiev for the code sample that helped me find the solution needed.

Happy Coding!

Leave a Reply