Step 4: Declaring the Workflow Event
In this step, you will declare the workflow event that triggers the transition from
the PendingPayment workflow state to the
ReadyForAssignment workflow state, define an event handler for
this event, and register the workflow event handler in the screen configuration. You
will also define the transition triggered by the workflow event.
Do the following:
- In the
RSSVWorkOrderDAC, declare a class that contains the new workflow event, as the following code shows.public class WorkflowEvents : PXEntityEvent<ARRegister>.Container<WorkflowEvents> { public PXEntityEvent<ARRegister> InvoiceGotPrepaid = null!; }Tip: Make sure that you have added the PX.Data.WorkflowAPIusingdirective. - In the
RSSVWorkOrderEntrygraph, declare an event handler for theInvoiceGotPrepaidworkflow event, as the following code shows.public PXWorkflowEventHandler<RSSVWorkOrder, ARRegister> OnInvoiceGotPrepaid = null!; - In the
RSSVWorkOrderEntry_Workflowclass, bind theOnInvoiceGotPrepaidworkflow event handler to theInvoiceGotPrepaidworkflow 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.WorkflowEvents>( workflowEvent => workflowEvent.InvoiceGotPrepaid) .Is(graph => graph.OnInvoiceGotPrepaid) .UsesPrimaryEntityGetter< SelectFrom<RSSVWorkOrder>. Where<RSSVWorkOrder.invoiceNbr .IsEqual<ARRegister.refNbr.FromCurrent>>>()); - In the
GetPendingPaymentBehaviorprivate static method, add the workflow event handler by using the WithEventHandlers method, as the following code shows..WithEventHandlers(handlers => { handlers.Add(graph => graph.OnInvoiceGotPrepaid); }); - In the lambda expression for the WithTransitions method,
declare the transition from the
PendingPaymentworkflow state to theReadyForAssignmentworkflow state in thetransitions.AddGroupFrom<States.pendingPayment>group, as the following code shows.transitionGroup.Add(transition => transition.To<States.readyForAssignment>() .IsTriggeredOn(graph => graph.OnInvoiceGotPrepaid)); - Save your changes.
