CacheAttached: To Replace Field Attributes in CacheAttached
The following activity will walk you through the process of replacing field attributes in CacheAttached event handlers.
Story
RSSVWorkOrder DAC holds the data of the Repair Work Orders
(RS301000) data entry form. The data of this DAC is also displayed on the Assign
Work Orders (RS501000) processing form. (You have developed both of these forms for
the Smart Fix company.) You need to add the following fields to this DAC: DefaultAssignee: The employee that has the fewest assigned repair work ordersAssignTo: The employee the repair work order will be assigned to
On the Assign Work Orders form, you need to calculate the values of these fields by using attributes. You do not need these calculations for the data entry form.
Process Overview
In this activity, you will add attributes that calculate the values of the
DefaultAssignee and AssignedTo fields of the
RSSVWorkOrder DAC. Because you need these calculations only for
the Assign Work Orders (RS501000) form, you will add these attributes by using the
CacheAttached event handler.
System Preparation
Before you begin replacing field attributes in CacheAttached event handlers, do the following:
- 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.
- Create a processing form without filtering parameters by performing the Processing Forms: To Create a Simple Processing Form prerequisite activity.
Step 1: Extending the DAC with New Fields
RSSVWorkOrder DAC as follows:- In the
RSSVWorkOrderclass, define theDefaultAssigneefield, as shown in the following code.#region DefaultAssignee [PXInt] [PXUIField(DisplayName = "Default Assignee")] public virtual int? DefaultAssignee { get; set; } public abstract class defaultAssignee : PX.Data.BQL.BqlInt.Field<defaultAssignee> { } #endregion - Define the
AssignTofield, as shown below.#region AssignTo [PXInt] [PXUIField(DisplayName = "Assign To")] public virtual int? AssignTo { get; set; } public abstract class assignTo : PX.Data.BQL.BqlInt.Field<assignTo> { } #endregion - Build the project.
Step 2: Replacing the Attributes
In this step, you will add the attributes to the RSSVWorkOrder DAC
fields by using the CacheAttached event handlers of these fields
in the RSSVAssignProcess graph. These attributes will be used for
the RSSVWorkOrder DAC fields only on the Assign Work Orders
(RS501000) form. Instead of completely replacing attributes, you will add the needed
attributes to the fields by including the PXMergeAttributes
attribute in the list of assigned attributes.
To implement the calculation of field values for the
RSSVAssignProcess graph, do the following:
- In the RSSVAssignProcess.cs file, add the
PX.TMusingdirectives. - To add the PXDBScalar attribute to the
DefaultAssigneefield, add the following event handler to theRSSVAssignProcessgraph.[PXMergeAttributes(Method = MergeMethod.Append)] [Owner(IsDBField = false, DisplayName = "Default Assignee")] [PXDBScalar(typeof(SelectFrom<OwnerAttribute.Owner>. LeftJoin<RSSVEmployeeWorkOrderQty>. On<OwnerAttribute.Owner.contactID.IsEqual< RSSVEmployeeWorkOrderQty.userID>>. Where<OwnerAttribute.Owner.acctCD.IsNotNull>. OrderBy<RSSVEmployeeWorkOrderQty.nbrOfAssignedOrders.Asc, RSSVEmployeeWorkOrderQty.lastModifiedDateTime.Asc>. SearchFor<OwnerAttribute.Owner.contactID>))] protected virtual void _( Events.CacheAttached<RSSVWorkOrder.defaultAssignee> e) { }For the system to calculate the value of the
To display the employee name instead of its ID (which is an integer) and display the selector for the column if it is editable, you have assigned the Owner attribute to theDefaultAssigneefield, you have used the PXDBScalar attribute. The PXDBScalar attribute selects the first record that matches the query specified in the attribute. In the query, you have selected records in ascending order by the number of assigned work orders.DefaultAssigneefield. Since theDefaultAssigneefield does not exist in the database, in the Owner attribute, you have specifiedIsDBField = false. - To add the PXUnboundDefault attribute to the
AssignedTofield, add the following event handler to theRSSVAssignProcessgraph.[PXMergeAttributes(Method = MergeMethod.Append)] [Owner(IsDBField = false, DisplayName = "Assign To")] [PXUnboundDefault(typeof(RSSVWorkOrder.assignee.When< RSSVWorkOrder.assignee.IsNotNull>. Else<RSSVWorkOrder.defaultAssignee>))] protected virtual void _( Events.CacheAttached<RSSVWorkOrder.assignTo> e) { }The system sets the value of the
AssignedTofield to the employee selected for the work order on the Repair Work Orders (RS301000) form (if the value is notnull) or to the default assignee specified in theDefaultAssigneefield (if the value selected on the Repair Work Orders form isnull). You have defined this behavior by using the PXUnboundDefault attribute. - Build the project.
