External and Internal Presentation of Field Values: To Define the External Presentation of Field Values (in FieldSelecting)

The following activity will walk you through the process of defining the external presentation of field values.

Story

Suppose that you need to modify how the Number of Assigned Work Orders column is displayed on the Assign Work Orders (RS501000) form. (You have developed this form for the Smart Fix company.) If the value in the corresponding field is null, you need to display 0 in the column. You will define the external presentation of values of the NbrOfAssignedOrders field of the RSSVWorkOrder DAC, which corresponds to the Number of Assigned Work Orders column.

Process Overview

For the configuration of the external presentation of values, you will use the FieldSelecting 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. If this value is null, the value in the Number of Assigned Work Orders column will be 0. You will assign the external presentation of the value to e.ReturnValue.

System Preparation

Before you begin defining the external presentation of field values, do the following:

  1. Prepare an MYOB Acumatica instance by performing the Test Instance for Customization: To Deploy an Instance for Developing Processing Forms 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: Configuring the External Presentation of 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 FieldSelecting event handler.
            protected virtual void _(Events.FieldSelecting<RSSVWorkOrder,
                             RSSVWorkOrder.nbrOfAssignedOrders> e)
            {
                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.ReturnValue = employeeNbrOfOrders.NbrOfAssignedOrders.
                        GetValueOrDefault();
                }
                else
                {
                    e.ReturnValue = 0;
                }
            }
    Tip: If you also need to change the internal presentation of the value, you need to assign it to e.NewValue in the FieldUpdating event handler. For unbound data fields that are only displayed in the UI, you can use only the FieldSelecting event that defines the UI presentation of the value. For details about the external and internal presentation of values, see External and Internal Presentation of Field Values: General Information.
  3. Build the project.