Step 5: Defining the Event Handler
In this step, you will define an event handler for the
ARInvoiceEntry.OnCloseDocument
event. Do the following:
- In the
RSSVWorkOrderEntry
graph, define an event handler, as the following code shows.#region Workflow Event Handlers public PXWorkflowEventHandler<RSSVWorkOrder, ARInvoice> OnCloseDocument; #endregion
In the first type parameter of the handler, you have specified the primary DAC of the form where the handler is used. As the second type parameter, you have specified the primary DAC of the form where the event is fired.Tip: Add theusing
directive for the PX.Data.WorkflowAPI namespace if it has not been added earlier. - In the
RSSVWorkOrderWorkflow
class, bind theOnCloseDocument
event handler to theCloseDocument
event in the screen configuration: After the AddDefaultFlow method, call the WithHandlers method. In the method, add theOnCloseDocument
event handler, as the following code shows..WithHandlers(handlers => { handlers.Add(handler => handler .WithTargetOf<ARInvoice>() .OfEntityEvent<ARInvoice.Events>(e => e.CloseDocument) .Is(g => g.OnCloseDocument) .UsesPrimaryEntityGetter< SelectFrom<RSSVWorkOrder>. Where<RSSVWorkOrder.invoiceNbr .IsEqual<ARRegister.refNbr.FromCurrent>>>()); })
In the code above, you have added a handler for an event that changes the state of the invoice. In the UsesPrimaryEntityGetter method, you have selected the repair work order whose state should be updated by the number of the invoice that has been closed.Tip: Make sure that you have added theusing
directives, which are shown in the following code.using PX.Objects.AR; using PX.Data.BQL.Fluent;
- In the definition of the
Completed
state, add the event handler using the WithEventHandlers method, as the following code shows.fss.Add<States.completed>(flowState => { 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.CreateInvoiceAction, a => a .IsDuplicatedInToolbar() .WithConnotation(ActionConnotation.Success)); }) // Add the OnCloseDocument event handler .WithEventHandlers(handlers => { handlers.Add(g => g.OnCloseDocument); }); });
- In the lambda expression for the WithTransitions method, add
the transition from the
Completed
state to thePaid
state, as the following code shows.transitions.AddGroupFrom<States.completed>(ts => { ts.Add(t => t.To<States.paid>() .IsTriggeredOn(g => g.OnCloseDocument)); });
- Save your changes.