Creating info parts to show key business data

Although AX is shipped with a standard set of info parts placed on key forms throughout the system, we often find that our users require different information to be made available. An example of an info part is displayed on the right-hand pane of the All loads list page found by navigating to Transportation management | Common | Loads | All loads.

The data that is displayed on the info part is determined by a query. We use the query to define the data that will be displayed, and also to define how this relates to the form where the info part is placed. To demonstrate this, we will add a part to the All loads list page that will show vehicle information.

First, we will construct a query that defines a path from the load table to our vehicle table. This will have to go through the appointment table's relations to link to the vehicle created in the previous chapter.

The query structure doesn't need to include the load table itself, as the appointment table already has a relation defined. Queries used in any part must be written for performance and should only contain fields actually used in the part. We therefore don't create a generic reusable query, but a query specifically for a part.

Our part will need the following fields:

  • Vehicle ID
  • Vehicle registration number
  • Vehicle status
  • Vehicle group
  • The next service date

Creating a query for the part

Before we start, we need to create a new relation on the TMSAppointment table that connects the ConFMSVehicleTableTruck foreign key to ConFMSVehicleTable.RecId. This is because the current relation is to the inherited truck table, and we really need a relation to the base vehicle table. This becomes more apparent when we add parts to the vehicle list page, as this will show a combined list of all vehicle types. The only commonality is that they all extend ConFMSVehicleTable.

There are two ways we can do this, add a new foreign key relation on TMSAppointment and update the code to set the foreign key, or use the same field as the relation to ConFMSVehicleTable. We can justify using the same key as we can say that the main vehicle is a truck. To do this, follow these steps:

  1. Create a relation on TMSAppointment to ConFMSVehicleTable and update the required properties as before. You must set the RelatedTableRole property. The relation should be done by right-clicking on the new relation and selecting New | Foreign Key | Single field AlternateKey based. We want RecId as the relation.
  2. Now edit the relation to change it from ConFMSVehicleTable to ConFMSVehicleTableTruck.
  3. As expected, it will have created a new field called ConFMSVehicleTable. We don't need this field now, as our relation is using ConFMSVehicleTableTruck as the foreign key. Delete this new field.

To create the query for the vehicle information info part, follow these steps:

  1. In your project, right-click on the Queries node and go to New | Query.
  2. Rename the query to ConFMSVehicleAppointmentPart. The Part suffix is a convention, and it is important to highlight to other developers that it is a part query.
  3. The first data source will be the one used to link the form's data source, so add TMSAppointment to the Data Sources node.

    Note

    AX automatically adds the suffix _1. This is to ensure that the name is unique. We should remove this suffix. If we have two data sources for the same table, we should use a suffix that identifies the table better than a number.

  4. On the Fields node, we change the Dynamic property to No, as we don't want any fields from this data source.

    Note

    Since our part doesn't require fields from this data source, we should not add any. This includes ApptRefNum and AppRetType, even though these fields are used in the relation to WHSLoadTable and WHSShipmentTable. Fields used in the relation don't need to be included in the fields list.

  5. Add ConFMSVehicleTable to the Data Sources node under TMSAppointment.
  6. On the Fields node, change the Dynamic property to Yes, noting that all of the table's fields have been automatically added under the Fields node. Now, change it to No and they are still there. This is a nice trick to add all the fields to the field list when we want most but not all fields.
  7. Remove all fields except VehicleId, VehicleStatusId, VehRegNo, and VehicleGroupId. Verify that Dynamic is set to No once finished.
  8. On the properties of ConFMSVehicleTable, set Relations to Yes.
  9. Check whether the relation (the Relations node) has been added. In this case, it should have assumed the ConFMSVehicleTable relation, which happens to be correct.

    Note

    If it didn't choose this relation, you will need to set the Relations property back to No and add the relation manually, using the ConFMSVehicleTable relation.

  10. Add ConFMSVehServiceTable to the Data Sources node under ConFMSVehicleTable.
  11. Do the trick with the Dynamic property on the Fields node and ensure that you only have the NextServiceDate field. Dynamic must be set to No once finished.
  12. On the properties of ConFMSVehServiceTable, set JoinMode to OuterJoin and Relations to Yes. We are using the outer join, as we will still want to show the vehicles without service data.
  13. We also only want one service record, so we set FirstOnly and FirstFast to Yes.
  14. To get the last service record, right-click on Order By and select New Field, setting the properties as follows: DataSource to ConFMSVehServiceTable, Field to NextServiceDate, and Direction to Descending.

The query structure should look like what is shown in the following screenshot:

Creating a query for the part

You may notice that we didn't include the fields used in the joins to our tables. AX will handle this for us.

Creating the info part

Next, we can create the info part, which is done by the following steps:

  1. In your project, right-click on Form Parts | Info Parts and select New | Info Part.
  2. Rename the part to ConFMSVehicleAppointmentPart.
  3. On the property sheet, set the Query property to ConFMSVehicleAppointmentPart.
  4. Under the Layout node, add a new group (right-click and choose New Group).
  5. Set Name to VehicleGroup.
  6. We only have one group, so a caption will not help the user and just take up space. Leave Caption blank, and leave ShowCaption as No.
  7. If we required a list of records in a grid, we would've set Repeating to Yes. In our case, we want just the information in a form view, so we leave it as No.

    Note

    If we had designed a field group for this purpose, we could use it to define this group. This can be useful when we have the same fields used in more than one part and it allows changes to be made once and reflected in all parts that use the field group.

  8. Right-click on VehicleGroup and choose New Field. Set DataSource to ConFMSVehicleTable and DataField to VehicleId. Copy the VehicleId field name to the Name property.
  9. Repeat this process for the remaining fields.
  10. On the VehicleId field, set Style as TitleField.

Creating the part's menu item

We now have to create a display menu item so that it can be added to a form. This is done as follows:

  1. In your project, right-click on Display, which is under Menu Items, and go to New | Menu Item.
  2. Rename the menu item to ConFMSVehicleAppointmentPart.
  3. Set Label to Vehicle information and create a new label (don't use the existing GLS label), remembering to set Comments to Con Vehicle information.
  4. Finally, set ObjectType to InfoPart and Object to ConFMSVehicleAppointmentPart.

Adding the info part to the All loads list page

To add the All loads list page, our first task is to locate it in the AOT. The easiest way is to navigate the Menus node in the AOT as if you are navigating through the interface. The properties of the All loads node reveal that the menu item is WHSLoadPlanningListPage. The Object property of this menu item has the same name, so this is the form.

Note

List pages are normally named after the table and suffixed with ListPage, but it is acceptable to deviate from this naming convention based on the situation.

To add the WHSLoadPlanningListPage info part, follow these steps:

  1. Drag the WHSLoadPlanningListPage form onto the Forms node of your project.
  2. Drag the ConFMSVehicleAppointmentPart menu item onto the Parts node of WHSLoadPlanningListPage.
  3. Move the part so that it is at the top of the list of parts using Alt and the arrow key; this simply arranges the part on the form to be at the top.
  4. Go to the properties of the new part and note that DataSource is WHSLoadTable, which is correct, as this is how we intend to relate to TMSAppointment.
  5. If you click on DataSourceRelation, it should set itself to TMSAppointment.WHSLoadTable. This is the relation defined between WHSLoadTable and TMSAppointment, which is also correct.

Completing the info part

First, we should test the info part. As part of our testing in Chapter 4, Creating Business Logic and Hooking into Core AX, we created a vehicle and linked it to an appointment. To test this part, we need to associate it to a load. This is done on the Reference fast tab in the Appointment Scheduling form.

To test the info part, right-click on the WHSLoadPlanningListPage form and select Open. Move through the records until you reach the load that was referenced against the appointment. It should display information as shown in the following screenshot:

Completing the info part

The vehicle ID appears as a heading, and the other fields appear as a form, which is as expected. After clicking on More, we are shown the Appointment Schedule form, but the Vehicle details form would be more appropriate.

We can change this by the following steps:

  1. On our info part, we expand the part, right-click on Layout, and show the property sheet.
  2. Set ShowMoreDataSource to ConFMSVehicleTable.
  3. Save the changes and open the list page again. Notice that the More button now opens the Vehicle details form.

If you open the other list pages by going to Transportation management | Common | Loads, you will see that they all contain our info part. These are secondary list pages, which are the same form configured to show subsets of the loads.

You can also add more actions to the part, but be careful not to clutter the design as this would detract from the purpose of showing key data.

To add another link to the Appointment Schedule form as an action, follow these steps:

  1. Right-click on the part's Actions node and choose New Action.
  2. In MenuItemName, enter TMSAppointment and copy the Name property also.
  3. Save the changes and open the list page.

A new link is added below the More link, labeled Appointment Scheduling, as shown in the following screenshot:

Completing the info part

Finally, we should add the info part to the All shipments list page. The form is WHSShipPlanningListPage and you simply have to drag the part's menu item as before onto the Parts node. Remember to click on the DataSourceRelation property to ensure that this is correct.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.18