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
RSSVWorkOrder
DAC, 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.WorkflowAPIusing
directive. - In the
RSSVWorkOrderEntry
graph, declare an event handler for theInvoiceGotPrepaid
workflow event, as the following code shows.public PXWorkflowEventHandler<RSSVWorkOrder, ARRegister> OnInvoiceGotPrepaid = null!;
- In the
RSSVWorkOrderEntry_Workflow
class, bind theOnInvoiceGotPrepaid
workflow event handler to theInvoiceGotPrepaid
workflow 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
GetPendingPaymentBehavior
private 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
PendingPayment
workflow state to theReadyForAssignment
workflow 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.