PXAccumulator: To Modify the Processing Form to Use the Field Updated by PXAccumulator

The following activity will walk you through the modification of the processing form to use the field updated by the custom PXAccumulator attribute.

Story

The Assign Work Orders (RS501000) processing form was developed for the Smart Fix company, and now its managers would like to make the automatic assignment of work orders on this form more efficient. The company's management wants the processed repair work orders to be automatically assigned to the employee with the fewest repair work orders assigned. If multiple employees have the smallest number of repair work orders assigned, the work orders will be assigned to the first of these employees to be selected from the database.

For the Assign Work Orders form, you have already implemented the custom PXAccumulator attribute, which counts the number of repair work orders assigned to each employee and updates this number in the database during processing. Now you need to modify the form so that it contains information about the number of work orders assigned to the potential assignees who are listed in the table.

You need to have the following columns related to the employees and the number of assigned work orders in the table on the Assign Work Orders form:
  • Assignee: The assignee that is selected on the Repair Work Orders (RS301000) form for the work order. The column can be empty if no value is selected on the Repair Work Orders form. The Assignee column will temporarily remain in the table on the Assign Work Orders form for testing purposes and will not be editable.
  • Default Assignee: The default assignee, which is calculated from the database values as the employee who has the lowest number of assigned work orders. For testing purposes (to make sure that the values in the Assign To column are calculated correctly), you will display the Default Assignee column in the table on the Assign Work Orders form and will not be editable. (You will delete this column after testing.)
  • Assign To: The assignee to which the repair work order will be assigned during the assignment operation. By default, the system displays in this column the value from the Assignee column for this work order if it is not null. If the value in the Assignee column is null, the system displays the default value from the Default Assignee column. A user can override the default value in this column.
  • Number of Assigned Work Orders: The number of work orders assigned to the assignee that is specified in the Assignee column. The Number of Assigned Work Orders column cannot be edited.

Process Overview

You will modify the constructor of the RSSVAssignProcess graph to make the Assign To column editable.

In the RSSVWorkOrderEntry graph, you will also modify the implementation of the AssignOrders() method and add the complete() action handler so that 1 is added to or subtracted from the number of assigned work orders. The value that is specified for the number of assigned work orders in the AssignOrders() method and the complete() action handler will be added to the value stored in the database by the custom PXAccumulator attribute.

You will then modify the ASPX code of the Assign Work Orders (RS501000) form and test the changes on the form.

System Preparation

Before you begin performing the steps of this activity, 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.
  3. Add filtering parameter to the form by performing the Filtering Parameters: To Add a Filter for a Processing Form prerequisite activity.
  4. Implement a custom accumulator attribute by performing the PXAccumulator: To Implement a Custom Accumulator Attribute prerequisite activity.
  5. Define the business logic for particular fields by performing the CacheAttached: To Replace Field Attributes in CacheAttached prerequisite activity.
  6. Define the presentation logic for particular fields by performing the External and Internal Presentation of Field Values: To Define the External Presentation of Field Values (in FieldSelecting) prerequisite activity.

Step 1: Enabling the Editing of the Field

Edit the RSSVAssignProcess graph as follows:
  1. In the constructor of the RSSVAssignProcess graph, replace the Assignee field with the AssignTo field of the RSSVWorkOrder DAC. The resulting code of the constructor is shown in the following code.
            public RSSVAssignProcess()
            {
                WorkOrders.SetProcessCaption("Assign");
                WorkOrders.SetProcessAllCaption("Assign All");
                PXUIFieldAttribute.SetEnabled<RSSVWorkOrder.assignTo>(
                    WorkOrders.Cache, null, true);
            }
  2. Build the project.

Step 2: Modifying the Assignment and Completion Operations

In this step, you will modify the AssignOrders() static method and add the complete() action handler of the RSSVWorkOrderEntry graph so that they change the number of assigned work orders for each employee who is assigned a repair work order or who completed a repair work order. You will assign 1 or -1 (depending on whether the work order is assigned or completed) to the RSSVWorkOrder.NbrOfAssignedOrders field; the custom accumulator attribute will add this value to the value stored in the database.

Do the following to modify the AssignOrders() method and add the complete() action handler:

  1. In the RSSVWorkOrderEntry graph, define the data view for the calculation of the number of assigned work orders per employee, as shown in the following code.
            //The view for the calculation of the number of assigned work orders 
            //per employee
            public SelectFrom<RSSVEmployeeWorkOrderQty>.View Quantity;
  2. In the AssignOrders() method of the RSSVWorkOrderEntry graph, add the following line in the beginning of the try clause.
                        workOrder.Assignee = workOrder.AssignTo;
  3. In the AssignOrders() method of the RSSVWorkOrderEntry graph, add the following code before the workOrderEntry.Actions.PressSave() call.
                        //Modify the number of assigned orders for the employee.
                        RSSVEmployeeWorkOrderQty employeeNbrOfOrders =
                            new RSSVEmployeeWorkOrderQty();
                        employeeNbrOfOrders.UserID = workOrder.Assignee;
                        employeeNbrOfOrders.NbrOfAssignedOrders = 1;
                        workOrderEntry.Quantity.Insert(employeeNbrOfOrders);
  4. In the RSSVWorkOrderEntry graph, replace the definition of the Complete action, as shown in the following code.
            public PXAction<RSSVWorkOrder> Complete;
            [PXButton]
            [PXUIField(DisplayName = "Complete", Enabled = false)]
            protected virtual IEnumerable complete(PXAdapter adapter)
            {
                // Get the current order from the cache
                RSSVWorkOrder row = WorkOrders.Current;
                //Modify the number of assigned orders for the employee
                RSSVEmployeeWorkOrderQty employeeNbrOfOrders =
                    new RSSVEmployeeWorkOrderQty();
                employeeNbrOfOrders.UserID = row.Assignee;
                employeeNbrOfOrders.NbrOfAssignedOrders = -1;
                Quantity.Insert(employeeNbrOfOrders);
                // Trigger the Save action to save changes in the database
                Actions.PressSave();
                return adapter.Get();
            }
  5. Rebuild the project.

Step 3: Adjusting the ASPX Page (Self-Guided Exercise)

Perform the following general steps on your own:
  1. Add the Default Assignee, Assign To, and Number of Assigned Work Orders columns to the table on the Assign Work Orders (RS501000) form, and adjust the width of the columns. (For the Number of Assigned Work Orders column, specify Width="100".)
    Note: You can add the columns on the Screen Editor page of the Customization Project Editor or edit the ASPX code of the form directly in Visual Studio. For details on working with the Screen Editor page or editing the ASPX code in Visual Studio, see the T200 Maintenance Forms training course.
  2. Remove CommitChanges="True" for the Assignee column.
  3. For the Assign To column, set the following properties:
    • CommitChanges: True
    • AutoRefresh: True
      Note: This property is specified for the PXSelector control inside RowTemplate. For details about how to specify the AutoRefresh property, see Step 2.2.1: Restricting the Values of a Field (with PXRestrictor) in the T210 Customized Forms and Master-Detail Relationship training course.
  4. Publish the customization project.

Step 4: Testing the Form and the Attribute

In this step, you will test the Assign Work Orders (RS501000) form and the custom accumulator attribute. Do the following:
  1. On the Repair Work Orders (RS301000) form, create three repair work orders with the settings specified in the following table. Save each of them and click Remove Hold on the form toolbar.
    Work Order 1 Work Order 2 Work Order 3
    Customer ID C000000001 C000000002 C000000001
    Service Battery Replacement Screen Repair Battery Replacement
    Device Nokia 3310 Samsung Galaxy S4 Motorola RAZR V3
    Assignee Andrews, Michael Empty Beauvoir, Layla
    Description Test order Test order Test order

    Notice that the created work orders have the Ready for Assignment status.

  2. On the Assign Work Orders (RS501000) form, make sure that the three repair work orders that you have created are displayed. Also, be sure that these work orders have the specified values in the Assignee, Default Assignee, and Assign To columns, as shown in the screenshot below.

    For the first work order, the Assign To setting is Andrews, Michael, which is the value specified in the Assignee column (that is, the value that you specified on the Repair Work Orders form).

    For the second work order, the Assign To setting is Baker, Maxwell, which is the value specified in the Default Assignee column. The database currently does not have the information about the number of repair work orders assigned to the employee. Therefore, this is the employee with the first UserID (which is the key field) in the database.

    For the third work order, the Assign To setting is Beauvoir, Layla, which is the value specified in the Assignee column.
    Figure 1. The assignees on the Assign Work Orders form


  3. For the third work order, change the value in the Assign To column to Becher, Joseph.
  4. On the form toolbar, click Assign All. The work orders should be processed successfully.
  5. In the Processing dialog box, make sure that the processed repair work orders have the assignees specified as follows:
    • First work order: Andrews, Michael
    • Second work order: Baker, Maxwell
    • Third work order: Becher, Joseph
  6. Review the records in the RSSVEmployeeWorkOrderQty table by using Microsoft SQL Server Management Studio. The table contains three records (one for each employee to which repair work orders have been assigned during this testing). The value in the NbrOfAssignedOrders column is 1 for each row.
  7. On the Repair Work Orders (RS301000) form, select one of the processed work orders. Click Complete on the form toolbar.
  8. In SQL Server Management Studio, review the records in the RSSVEmployeeWorkOrderQty table. Now for one of the rows, the value of NbrOfAssignedOrders is 0.

Step 5: Removing the Unnecessary Columns from the Form (Self-Guided Exercise)

You should now remove the Assignee and Default Assignee columns from the table on the Assign Work Orders (RS501000) form on your own.

You can remove the columns on the Screen Editor page of the Customization Project Editor or edit the ASPX code of the form directly in Visual Studio. For details on working with the Screen Editor or editing the ASPX code in Visual Studio, see the T200 Maintenance Forms training course.