Step 5: Defining the Workflow Event Handler
In this step, you will define a workflow event handler for the
ARInvoiceEntry.OnCloseDocument
workflow event. Do the
following:
- In the
RSSVWorkOrderEntry
graph, define a workflow event handler, as the following code shows.#region Workflow Event Handlers public PXWorkflowEventHandler<RSSVWorkOrder, ARInvoice> OnCloseDocument = null!; #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
RSSVWorkOrderEntry_Workflow
class, bind theOnCloseDocument
workflow event handler to theCloseDocument
workflow 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>( workflowEvent => workflowEvent.CloseDocument) .Is(graph => graph.OnCloseDocument) .UsesPrimaryEntityGetter< SelectFrom<RSSVWorkOrder>. Where<RSSVWorkOrder.invoiceNbr .IsEqual<ARRegister.refNbr.FromCurrent>>>()); })
In the code above, you have added a handler for a workflow event that changes the state of the invoice workflow. 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.WorkflowAPI;
- In the
GetCompletedBehavior
private static method, add the event handler by using the WithEventHandlers method, as the following code shows..WithEventHandlers(handlers => { handlers.Add(graph => graph.OnCloseDocument); });
- In the lambda expression for the WithTransitions method, add
the transition from the
Completed
workflow state to thePaid
workflow state, as the following code shows.transitions.AddGroupFrom<States.completed>( transitionGroup => { transitionGroup.Add(transition => transition.To<States.paid>() .IsTriggeredOn(graph => graph.OnCloseDocument)); });
- Save your changes.