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:
- 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.WorkflowAPIusing
directive. - In the
RSSVWorkOrderEntry
graph, declare an event handler for theInvoiceGotPrepaid
event, as the following code shows.public PXWorkflowEventHandler<RSSVWorkOrder, ARRegister> OnInvoiceGotPrepaid;
- In the
RSSVWorkOrderWorkflow
class, bind theOnInvoiceGotPrepaid
event handler to theInvoiceGotPrepaid
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>>>());
- 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); }); });
- In the lambda expression for the WithTransitions method,
declare the transition from the
PendingPayment
state to theReadyForAssignment
state in thetransitions.AddGroupFrom<States.pendingPayment>
group, as the following code shows.ts.Add(t => t.To<States.readyForAssignment>() .IsTriggeredOn(g => g.OnInvoiceGotPrepaid));
- Save your changes.