| Step 1.3.2: Define the Data View Delegate | 38
Step 1.3.2: Define the Data View Delegate
To display both sales orders and repair work orders in one grid, you need to define a data view delegate
in which you use two separate queries: a query to select sales orders and a query to select repair work
orders. After you select each query, you return the result with the yield key word, which allows you to
return each record without exiting the method. Thus, you don't need to create a temporary collection
with the results of the query.
About Data View Delegates
By default, when a data view object is requested by the UI or you invoke the Select() method on the
object, the system executes the query specified in the data view declaration. However, you can define
a dynamic query, which is an optional graph method (called the data view delegate) that is executed
when the data view is requested. If no dynamic query is defined in the graph, Acumatica Framework
executes the fluent BQL statement from the data view declaration.
We recommend that you use data view delegates in the following cases:
• If the query retrieves data fields that cannot be calculated declaratively by attributes—for
instance, if you are retrieving values aggregated by calculated data fields
• If the result set has data records that aren’t retrieved from the database and are composed
dynamically in code
In a graph extension, to define the delegate for a data view, you should redeclare the data view and
add a method that has the same name as the data view, except with a different case for the first letter
(for example, if the data view name is MyDataView, the name of the delegate must be myDataView).
For details on data view delegates, see Data View Delegates and To Add a Data View Delegate .
Defining the Data View Delegate
To define the needed data view delegate, do the following:
1. To compose a query that selects sales orders and invoices created for these sales orders, learn
the names of the DACs you will use in the query.
In Acumatica ERP, an invoice cannot be created directly for a sales order. A user first creates
a shipment and then creates an invoice for the shipment. The invoice number is stored in the
SO shipment record. Therefore, you need to use the DAC that contains information about SO
shipments. To learn the DAC name, do the following:
a. In Acumatica ERP, open the Sales Orders (SO301000) form.
b. Open the Shipments tab, which contains information about shipments and the
corresponding invoices.
c. While pressing Ctrl + Alt, select the Invoice Nbr. column.
In the Element Properties dialog box, which opens, note that the DAC name is
SOOrderShipment and that the Invoice Nbr. column field name is InvoiceNbr.
2. Open the source code of the SOOrderShipment DAC and investigate its fields. You can see
that the DAC contains both the sales order number (in the OrderNbr field) and the invoice
number (in the InvoiceNbr field). You will use this information later to construct a fluent BQL
statement.
3. In the RSSVPaymentPlanInq graph, define a method that converts an object of the
SOOrderShipment DAC to an object of the RSSVWorkOrderToPay DAC.
public static RSSVWorkOrderToPay RSSVWorkOrderToPay(SOOrderShipment shipment)
{
RSSVWorkOrderToPay ret = new RSSVWorkOrderToPay();
ret.OrderNbr = shipment.OrderNbr;