Workflow via Code – Part 3

In part 1, we created a basic shell of a workflow, and in part 2, we added actions. Now it is time to enhance the actions by setting which states the actions should be enabled and creating field assignments to set field values when the actions are clicked.

Add Actions by Status

To assign valid actions to a state, we expand the states.Add section to include .WithActions as shown below. With the .IsDuplicatedInToolbar(), we can additionally place the button on the main toolbar as well.

View this gist on GitHub

Hide the Legacy Hold Checkbox

While we are in the state, let’s get rid of that annoying Hold checkbox that may be left on the screen. Acumatica removed the field from the ASPX file, but there is another way we can do this via the workflow, and the example can be reused for other fields. See the .WithFieldStates section below which is placed into each state of the .WithFlowStates section immediately after the .WithActions section. (See the full example at the end of the post for placement.)

View this gist on GitHub

Assign Field Values on Click of Actions

After defining similar sections to each state for adding actions by state and controlling visibility of fields, it’s time to transition field values when the actions are clicked. Similarly to transitioning an initial value of status to Hold in part 1 of this series, we will add additional transitions. Since the transition group is already created from part 1, all we need to add now is transitions, and not another transition group. The transitions are tacked on to the transaction group from part 1, after all the actions have been defined. Note that you will get an error if you trigger a transition from a state using an action that is not assigned to that state.

View this gist on GitHub

In the example above, we have added the transitions.Add section after the tranisitions.AddGroupFrom section of the workflow shell from part 1 of the series. By including the .From state identifier and the .To state identifier, we tell the workflow that we we want to perform this transition when the specified .IsTriggerdOn action is clicked while the document is in the .From state. The .WithFieldAssignments section is used to assign values to fields. In this example, we must ensure that the removeHold action is specified under the hold state.

In the screenshot below, we can see that the hold and schedule actions are disabled because the Work Order is in Hold status. Also, the Remove Hold action has been duplicated to the toolbar. When clicking Remove Hold, the status changes to Open. When clicking Hold, the status changes back to Hold.

The complete code at this point is shown in the following gist.

View this gist on GitHub


By now, our workflow is starting to take shape. In this part of the series, we added actions to specific document states and used transitions to assign field values. We also hid the legacy Hold checkbox from the screen to keep up with Acumatica’s modernization of the interface since we now toggle hold via actions instead of the checkbox. In the full code above, you see actions added to each state as we did with the one example as well as transitions when we need the workflow to change field values. In part 4, we will add conditions so that certain conditions must be met for parts of our workflow to be activated.

Happy Coding!

Leave a Reply