Step 3: Adding a Workflow for the Specific Value of the Workflow-Identifying Field

In this step, you will add a workflow for the Simple value of the Order Type box. This workflow has three states (On Hold, Completed, Paid) and two transitions (from On Hold to Completed triggered by the Complete action, from Completed to Paid triggered by the OnCloseDocument event). You will add these states and transitions to the screen configuration in the extension of the RSSVWorkOrderWorkflow class.

Note:
You do not need to add actions and event handlers used in this workflow because they are already added in the original screen configuration defined in the RSSVWorkOrderWorkflow class.

To add the new workflow, do the following in the Configure method of the RSSVWorkOrderWorkflow_Extension class:

  1. In the lambda expression for the UpdateScreenConfigurationFor method, after calling the FlowTypeIdentifierIs method, call the WithFlows method and add a workflow for the Simple value of the UsrOrderType field as shown in the following code.
    .WithFlows(flows => flows
      .Add<OrderTypes.simple>(flow => flow ... )));

    You specify the value for the workflow-identifying field as the type parameter of the Add method.

  2. Inside the lambda expression for the Add method, specify the list of states of the new workflow as shown in the following code.
                  .WithFlowStates(states =>
                   {
                     states.Add<RSSVWorkOrderWorkflow.States.onHold>(flowState =>
                     {
                            return flowState
                            .IsInitial()
                            .WithActions(actions =>
                            {
                                actions.Add(g => g.Complete, a => a
                                .IsDuplicatedInToolbar()
                                .WithConnotation(ActionConnotation.Success));
                            });
                     });
                     states.Add<RSSVWorkOrderWorkflow.States.completed>(flowState =>
                     {
                            return flowState
                            .WithFieldStates(fieldstates =>
                            {
                                fieldstates.AddField<RSSVWorkOrder.customerID>(state =>
                                state.IsDisabled());
                                fieldstates.AddField<RSSVWorkOrder.serviceID>(state =>
                                state.IsDisabled());
                                fieldstates.AddField<RSSVWorkOrder.deviceID>(state =>
                                state.IsDisabled());
                            })
                            .WithActions(actions =>
                            {
                                actions.Add(g => g.CreateInvoiceAction, a => a
                                 .IsDuplicatedInToolbar()
                                 .WithConnotation(ActionConnotation.Success));
                            })
                            .WithEventHandlers(handlers =>
                            {
                                handlers.Add(g => g.OnCloseDocument);
                            });
                      });
                      states.Add<RSSVWorkOrderWorkflow.States.paid>(flowState =>
                      {
                            return flowState
                            .WithFieldStates(fieldstates =>
                            {
                                fieldstates.AddField<RSSVWorkOrder.customerID>(state =>
                                state.IsDisabled());
                                fieldstates.AddField<RSSVWorkOrder.serviceID>(state =>
                                state.IsDisabled());
                                fieldstates.AddField<RSSVWorkOrder.deviceID>(state =>
                                state.IsDisabled());
                            });
                      });
                  })

    In the code above, you add three states: OnHold, Completed, and Paid. For the OnHold state, you specify that the Complete action should be available in this state. For the Completed state, you specify which fields should be disabled and that the CreateInvoice action and the OnCloseDocument event handler should be available in this state. For the Paid state, you specify which fields should be disabled.

  3. After the call of the WithFlowStates method, define the transitions using the WithTransitions method as the following code shows.
                  .WithTransitions(transitions =>
                  {
                    transitions.AddGroupFrom<RSSVWorkOrderWorkflow.States.onHold>(ts =>
                    {
                      ts.Add(t => t.To<RSSVWorkOrderWorkflow.States.completed>()
                            .IsTriggeredOn(g =>g.Complete));
                    });
                    transitions.AddGroupFrom<RSSVWorkOrderWorkflow.States.completed>(ts =>
                    {
                      ts.Add(t => t.To<RSSVWorkOrderWorkflow.States.paid>()
                            .IsTriggeredOn(g =>g.OnCloseDocument));
                    });
                  })
  4. Build your project.