Step 4: Declaring the Event

In this step, you will declare the event that triggers the transition from the PendingPayment state to the ReadyForAssignment state, define an event handler for this event, and register the event handler in the screen configuration. You will also define the transition triggered by the event.

Do the following:

  1. In the RSSVWorkOrder DAC, declare the class that contains the custom event, as the following code shows.
            public class MyEvents : PXEntityEvent<ARRegister>.Container<MyEvents>
            {
                public PXEntityEvent<ARRegister> InvoiceGotPrepaid;
            }
    Tip: Make sure that you have added the PX.Data.WorkflowAPI using directive.
  2. In the RSSVWorkOrderEntry graph, declare an event handler for the InvoiceGotPrepaid event, as the following code shows.
            public PXWorkflowEventHandler<RSSVWorkOrder, ARRegister> OnInvoiceGotPrepaid;
  3. In the RSSVWorkOrderWorkflow class, bind the OnInvoiceGotPrepaid event handler to the InvoiceGotPrepaid event in the screen configuration: In the lambda expression for the WithHandlers method, add the handler, as the following code shows.
                        handlers.Add(handler => handler
                          .WithTargetOf<ARRegister>()
                          .OfEntityEvent<RSSVWorkOrder.MyEvents>(e => e.InvoiceGotPrepaid)
                          .Is(g => g.OnInvoiceGotPrepaid)
                          .UsesPrimaryEntityGetter<
                            SelectFrom<RSSVWorkOrder>.
                            Where<RSSVWorkOrder.invoiceNbr
                            .IsEqual<ARRegister.refNbr.FromCurrent>>>());
  4. In the definition of the PendingPayment state, add the event handler using the WithEventHandlers method, as the following code shows.
                            {
                                return flowState
                                  .WithFieldStates(states =>
                                  {
                                    states.AddField<RSSVWorkOrder.customerID>(state 
                                      => state.IsDisabled());
                                    states.AddField<RSSVWorkOrder.serviceID>(state 
                                      => state.IsDisabled());
                                    states.AddField<RSSVWorkOrder.deviceID>(state 
                                      => state.IsDisabled());
                                  })
                                  .WithActions(actions =>
                                  {
                                    actions.Add(g => g.PutOnHold, 
                                      a => a.IsDuplicatedInToolbar());
                                    actions.Add(g => g.CreateInvoiceAction, a => a
                                      .IsDuplicatedInToolbar()
                                      .WithConnotation(ActionConnotation.Success));
                                  })
                                  // Add the OnInvoiceGotPrepaid event handler
                                  .WithEventHandlers(handlers =>
                                  {
                                      handlers.Add(g => g.OnInvoiceGotPrepaid);
                                  });
                            });
  5. In the lambda expression for the WithTransitions method, declare the transition from the PendingPayment state to the ReadyForAssignment state in the transitions.AddGroupFrom<States.pendingPayment> group, as the following code shows.
                                ts.Add(t => t.To<States.readyForAssignment>()
                                  .IsTriggeredOn(g => g.OnInvoiceGotPrepaid));
  6. Save your changes.