Step 3: Exploring and Debugging the Code
Now that you have prepared the PhoneRepairShop_Code
project for debugging in Visual Studio, you can continue exploring the code of
the Release
action to find the event that you should use in the
custom workflow. Do the following:
- In the code of the
Release
method, find the call of theARDocumentRelease.ReleaseDoc
method.TheReleaseDoc
static method of theARDocumentRelease
static class is used to process the list of records in an invoice which are displayed on the Details tab of the form.Tip: You may notice that theReleaseDoc
operation starts within the StartOperation static method of the PXLongOperation static class to be executed in a background thread. - Go to the definition of the
ARDocumentRelease.ReleaseDoc
method, which is in the ARDocumentRelease.cs file.Notice that for the created instance, the
ReleaseDoc
method invokes theARReleaseProcess.ReleaseDocProc
static method, which is applied for each document in the list of the documents to be released. - Go to the definition of the
ARReleaseProcess.ReleaseDocProc
method.Notice that the
ARReleaseProcess.ReleaseDocProc
method receives the document as a record of theARRegister
data access class. During the document processing, the method creates a working copy of the record, specifies the fields of the record in the copy, and then restores the record in the cache from the completely ready copy. Inside the method, you can find the call to theProcessPayment
method. - Go to the definition of the
ARReleaseProcess.ProcessPayment
method, and explore its code. The method processes the release of a payment.Continue exploring the methods that are called inside the
ARReleaseProcess.ProcessPayments
method. You can find theARReleaseProcess.CloseInvoiceAndClearBalances
method. The call hierarchy is shown in the following screenshot.Notice the following line in the code of the CloseInvoiceAndClearBalances method.
RaiseInvoiceEvent(ardoc, ARInvoice.Events.Select(ev => ev.CloseDocument));
If you go to the definition of the RaiseInvoiceEvent method, you can find that the CloseDocument event is fired in this method, as shown in the following line of the method.
invEvent.FireOn(this, (ARInvoice)doc);
- To make sure that CloseDocument is the event that changes the
invoice status to Closed, do the following:
- Navigate to the ARInvoiceEntry_Workflow.cs file, which contains the definition of the workflow for the Invoices (SO303000) form.
- In the WithHandlers method, locate the handler for the CloseDocument event. The handler's name is OnCloseDocument.
- Locate the transition from the
Open
state to theClosed
state. Notice that the transition is triggered by the OnCloseDocument event handler, as shown in the following screenshot.
- To make sure that the firing of the
CloseDocument
event in theARReleaseProcess.CloseInvoiceAndClearBalances
method indeed happens when an invoice is fully paid, do the following:- Add a breakpoint to the line that fires the
OnCloseDocument
event of theARReleaseProcess.CloseInvoiceAndClearBalances
method. - Prepare a payment for debugging by doing the following:
- Open the invoice you created in Workflow Actions: To Configure the Conditional Appearance of the Action by searching for its number on the Invoices form.
- On the form toolbar of the Invoices form, click
Remove Hold.
The invoice is assigned the Balanced status.
- On the form toolbar, click Release. The invoice is released.
- On the More menu, click Pay.
The Payments and Applications (AR302000) form opens.
- On the form toolbar of the Payments and Applications form, click Remove Hold, and then click Release.
- In Visual Studio, notice that a breakpoint in the
ARReleaseProcess.CloseInvoiceAndClearBalances
method was hit when an invoice was closed. - Stop debugging.
- Add a breakpoint to the line that fires the