To Fetch Calculated Data from a Non-Scalar Source (in RowSelecting)

The following activity will walk you through the process of fetching calculated data from a non-scalar source by using the RowSelecting event handler.

Story

Suppose that you need to fetch the values for the Number of Assigned Work Orders column, which is displayed on the Assign Work Orders (RS501000) form. (You have developed this form for the Smart Fix company.) You need to write a fluent BQL query that fetches the number of assigned work orders from the RSSVEmployeeWorkOrderQty DAC for the employee selected in the AssignTo field of the RSSVWorkOrder DAC.

Process Overview

To fetch the needed values, you will use the RowSelecting event handler. In the event handler, you will retrieve the number of assigned work orders for the employee selected in the AssignTo field of the RSSVWorkOrder DAC.

System Preparation

Before you begin defining the logic for fetching data from a non-scalar source, do the following:

  1. Prepare an MYOB Acumatica instance by performing the Test Instance for Customization: To Deploy an Instance with a Custom Form that Implements a Workflow prerequisite activity.
  2. Create a processing form without filtering parameters by performing the Processing Forms: To Create a Simple Processing Form prerequisite activity.

Step 1: Extending the RSSVWorkOrder DAC

Add the new field to the RSSVWorkOrder DAC as follows:
  1. Define the NbrOfAssignedOrders field, as the following code shows.
            #region NbrOfAssignedOrders
            [PXInt]
            [PXUIField(DisplayName = "Number of Assigned Work Orders")]
            public virtual int? NbrOfAssignedOrders { get; set; }
            public abstract class nbrOfAssignedOrders :
                PX.Data.BQL.BqlInt.Field<nbrOfAssignedOrders>
            { }
            #endregion
  2. Build the project.

Step 2: Fetching Values for the NbrOfAssignedOrders Field

Modify the RSSVAssignProcess graph as follows:
  1. In the RSSVAssignProcess.cs file, add the PX.Data.BQL using directive.
  2. In the graph, define the following RowSelecting event handler.
            protected virtual void _(Events.RowSelecting<RSSVWorkOrder> e)
            {
                using (new PXConnectionScope())
                {
                    if (e.Row == null) return;
                        RSSVEmployeeWorkOrderQty employeeNbrOfOrders =
                            SelectFrom<RSSVEmployeeWorkOrderQty>.
                            Where<RSSVEmployeeWorkOrderQty.userID.IsEqual<@P.AsInt>>.
                            View.Select(this, e.Row.AssignTo);
    
                    if (employeeNbrOfOrders != null)
                    {
                        e.Row.NbrOfAssignedOrders = 
                          employeeNbrOfOrders.NbrOfAssignedOrders.GetValueOrDefault();
                    }
                    else
                    {
                        e.Row.NbrOfAssignedOrders = 0;
                    }
    
                }
            }
  3. Build the project.