To Define a Workflow from Code

You can customize a workflow not only by using the built-in editors of the Customization Project Editor but also by extending a graph. You can also define a new workflow. MYOB Acumatica Framework provides the PX.Data.WorkflowAPI library to customize workflows.

To create a workflow from code, you define workflow objects and specify their properties. Then you apply your changes to a workflow definition by using calling workflow methods.

Workflow Objects

A workflow definition may include the following objects:

  • Forms: Corresponds to a dialog box.

    A Forms object can include fields whose values a user should specify in the dialog box.

  • Conditions: Corresponds to a condition.
  • Actions: Corresponds to an action. An Actions object can include the following object:
    • FieldAssignments: A set of fields and their values, which should be assigned when the action is performed.
    • Assignments: A set of fields and their values to be used when performing navigation to another form. This object can be used for redirecting actions only. For details, see Types of Actions.
    • ParameterAssignments: A set of action parameters and their values, which should be assigned before the action method is invoked. This object can be used for only graph actions, because only those actions have a method to be invoked.
  • Fields: Corresponds to a DAC field.
    Note: You can specify default values of fields only for the initial state of a workflow.
  • Flows: Corresponds to a workflow.

    A Flows object consists of States objects, each of which includes the following entities:

    • Fields
    • Actions
    • Transitions

Workflow Methods

You can apply the following methods to each of the workflow objects:

  • Add: The method adds an object to a workflow.
  • Remove: The method removed an object from a workflow.
  • Replace: The method replaces one object with another in a workflow.
  • Update: The method updates the definition of an object in a workflow.

Customization of a Workflow

To customize a workflow from code, you need to do the following:

  1. In a customization project, create an extension library to be able to develop code in Visual Studio.

    For details on creating an extension library, see To Create an Extension Library. You can also develop customization code in the Code Editor. For details on the Code Editor, see Code Editor.

  2. In an extension library, create an extension of a graph where the workflow is defined.

    For details on creating a graph extension in the Code Editor, see To Start the Customization of a Graph. For details on graph extensions, see Graph Extensions.

  3. In the graph extension, override the void Configure(PXScreenConfiguration config) method.
  4. In the overridden method, get the context value of the workflow by calling the config.GetScreenConfigurationContext method.

    The method has two parameters: The first parameter refers to the graph type, and the second parameter refers to the primary DAC of the form.

  5. Declare the new entities you want to add to the workflow, such as dialog boxes, actions, and states.
  6. Apply the customization by calling the context.UpdateScreenConfigurationFor or context.ReplaceScreenCofigurationFor method. In the method's lambda expression, you apply workflow methods to workflow entities. For example, add the entities you declared in the previous instruction.
  7. Build the project and publish the customization project.

See detailed example in Customization Description.