In this post we are going to create 4 forms, 2 info parts, 2 menu items, 2 queries, and finally will create a new form part in the CustTableListPage to see how everything links together.

First we are going to create the Eduardo_VehicleTypeTable, Eduardo_VehicleModelsTable, and Eduardo_VehicleMakeTable, and Eduardo_CustCarTable forms. The four have the same requirements, and the only element that changes is the data source table they use.

In addition, three these forms (Eduardo_VehicleTypeTable, Eduardo_VehicleModelsTable, and Eduardo_VehicleMakeTable) will have an ActionPane with only two buttons; (1) new and, (2) delete.

The Eduardo_CustCarTable form, however, will contain an extra ActionPaneTab to hold the butons to open the orther three forms.

Steps:

1.In the AOT, right-click the Forms node and select New Form.

2.Rename the form to Eduardo_VehicleTypeTable.

3.In a second AOT, locate the tableEduardo_VehicleTypeTable.

4.Drag the table Eduardo_VehicleTypeTable to the DataSources node on the Eduardo_VehicleTypeTableform.

5.Expand the Designs node on the Eduardo_VehicleTypeTableform.

6.Right-click the Designs node and select New Control > ActionPane.

7.Expand the ActionPaneTab and then the ButtonGroup.

8.Right-click the ButtonGroup node and select New Control > CommandButton.

9.Set the following properties:

a.ButtonDisplay: Text & Image Left

b.Text: New

c.NormalImage: 11045

d.ImageLocation: EmbeddedResource

e.Primary: Yes

f.Command: New

10.Right-click the ButtonGroup node and select New Control > CommandButton.

11.Set the following properties:

a.ButtonDisplay: Text & Image Left

b.Text: Delete

c.NormalImage: 10121

d.ImageLocation: EmbeddedResource

e.SaveRecord: No

f.Primary: Yes

g.Command: Delete Record

12.Right-click the Designs node and select New Control > Group. Change the Name to Body.

13.Right-click the Group [Body] node and select New Control > Group. Change the Name to GridContainer.

14.Right-click the Group [Body] node and select New Control > Group. Change the Name to Splitter.

NOTE: To make the Splitter work, you will need to overwrite the Form's init method with the following code:

15.Right-click the Group [GridContainer] node and select New Control > Grid.

16.Expand the DataSources > Eduardo_VehicleTypeTable > Fields node.

17.Drag all the fields to the grid control.

18.Save your changes to the form.

19.Open the form by pressing Ctrl+O.

20.If you haven’t already done so, populate the table by entering your own data in to the form.

Repeat steps 1- 20 for the other three forms (Eduardo_VehicleMakeTable and Eduardo_VehicleModelsTable, and Eduardo_CustCarTable).The following image depicts the Eduardo_VehicleModelsTable form, so you get an idea how the three forms created above should look like.

Then if you open the Eduardo_VehicleModelsTable you should see the following (if you have some data)

Now, we are going to add anew ActionTab to the existing ActionPane control in the Eduardo_CustCarTable form. This action will create a new tab and three buttons (within the tab) that will open the three forms we created earlier.

Steps

1.Right-click the ActionPane node and select New Control > ActionPaneTab.

2.Change the following properties:

a.Name: Vehicles

b.Caption: Vehicle Management

3.Create 4 new Display Menu Items by draggingeach form to the Menu Items >Display Node.

4.Drag the Eduardo_VehicleMakeTable, Eduardo_VehicleTypeTable, Eduardo_VehicleModelsTableMenu Itemsto the ButtonGroup located in the Form Eduardo_CustCarTable form > Designs>ActionPane>ActionPaneTab:Vehicles> ButtonGroup

The following image shows how a Menu Item is created after I dragged the first form to the MenuItem>Display node.

5.Set the following properties for each Menu Item Button:

a.NormalImage: This will allow you to “attach” an image to the button.

b.Big: Yes (This will make it big)

The form should look like the following image:

Now that all our forms are ready, we are going to start developing to display data in a FactBox in both the Eduardo_CustCarTable and the CustTableListPage forms.To better understand what we are doing, I would like to review what a List Page is before moving forward with the FactBoxes.

List pages are the primary method of displaying data in Microsoft Dynamics AX. They can show lots of data from many tables, in a number of formats. They have consistent designs and functions. They can easily be displayed in the enterprise portal.

The components of a list page are:

1.The Grid displays a list of records. It displays only a few of the most important fields for each record.

2.The Filter bar is used to enter search criteria. This filters the list in the data grid to show only the records which an end-user is interested in.

3.The Preview Pane displays more fields about the selected record. This helps to ensure you have selected the correct record in your search.

4.FactBoxes display more information about the selected record from related tables.

5.The Action Pane contains menu items you can use to do typical tasks related to the highlighted record.

Now, let’s create a FactBox for the Eduardo_CustCarTable. The main idea of this FactBox is to show only the related detail data of Car's model for a selected record.

We need to first create a query. Because we need to for this project, we’ll create the two.

Steps:

1.In the AOT, right-click the Queries node and select New Query, and rename the new query to Eduardo_VehicleModelsQuery.

2.In a second AOT, locate the Eduardo_VehicleModelsTable.

3.Drag the Eduardo_VehicleModelsTable to the DataSources node on the Eduardo_VehicleModelsQuery .

4.Expand the Eduardo_VehicleModelsTable_1 data source.

5.In the property sheet for the fields node set the Dynamic property to Yes. This means all fields in the table will be included in the query.

Repeat steps 1 to 5 for the Eduardo_CustCarQuery.

Now it is time to create a Part for each of the queries we just created.

Steps:

1.Right-click the Info Parts node and select New Info Part.

2.In the property sheet for the new info part, set the Name property to Eduardo_VehicleModelsInfoPart, set the Caption property to Cars Models, set the Query property to Eduardo_VehicleModelsQuery.

3.Right-click the Layout node in the info part, and select New Group.

4.In the property sheet for the group, set the Repeating property to Yes.

5.Right-click the new group and select New Field.

6.Set the data source and data field for each of the fields exist in the Eduardo_VehicleModelsTable_1 data source (VehicleModelID, VehicleTypeID, VehicleMakeID, Status, Description)

Repeat steps 1 to 6 for the Eduardo_CustCarsInfoPart. The InfoPart should look like the following image:

NOTE: For the Eduardo_VehicleModelsInfoPart to work correctly in Eduardo_CustCarTable form, we need to tell the Eduardo_VehicleModelsTable that the relationship we have with the index Eduardo_VehicleModelIdx is on the EDT (See next image)

Now the step we all have been waiting for, lets add a new FactBox to the Eduardo_CustCarTable form.

Steps:

1.Create a new menu item for the info part, by dragging the Eduardo_VehicleModelsInfoPart to the Menu Items > Display node in the AOT.

2.Locate the Eduardo_CustCarTable form in the AOT.

3.Drag the Eduardo_VehicleModelsInfoPartmenu itemto the Parts node in the Eduardo_CustCarTable form.

4.In the property sheet for the new part reference, set the DataSourceRelation property to Eduardo_CustCarTable.Eduardo_VehicleModels.

5.Save your changes to the Eduardo_CustCarTable form.

Press CTRL+O to open the Eduardo_CustCarTable, and if everything went OK the form should look like the following image:

Pretty cool, isn't? If you click on a different record, the FactBox information will change to the specified relationship with the VehicleModelID field. Now, let's do the same with the CustTableListPage.

Steps:

1.Create a new menu item for the info part, by dragging the Eduardo_CustCarsInfoPart to the Menu Items > Display node in the AOT.

2.Locate the Eduardo_CustCarTabletablein the AOT.

3.Expand Eduardo_CustCarTabletable.

4.Right-click the Indexes node and select New Index

5.Rename the index to CustIdx

6.From the fields node on the table, drag the CustAccount field to the CustIdx index.

7.Save your changes to the table.

8.Locate the CustTableListPage form in the AOT.

9.Drag the Eduardo_CustCarsInfoPart menu item to the Parts node

10.In the property sheet for the new part reference, set the DataSourceRelation property to EDT.VetCustPetTable.CustAccount.

The CustTableListPage should look like this:

This concludes this series of posts about FactBoxes in AX 2012. I hope you have enjoyed this tutorial and that you will share it.

Thursday, December 29, 2011

In my last post (http://axwonders.blogspot.com/2011/12/walkthrough-creating-fact-boxes-in-ax_28.html ), we created 3 EDT’s, 4 tables and created the relationships we needed to hold the Auto Rental data.In this short post we are going to talk about primary indexes, and then we will create one for the Eduardo_CustCarTable. In addition, we are going to learn a little bit more about Form’s Parts in AX 2012 before jumping into creating the user interface forms for the Auto Rental data.

NOTE: When a primary index is not specified, AX uses a Surrogate Key as the primary index. This key is the RecId field and, if the table is saved per company, the DataAreaId. The surrogate key is used on many relations between tables.

To set the primary index on a table, open the property sheet for the table. The PrimaryIndex property allows any unique index with a key that is mandatory and cannot be edited.

1.In the AOT, locate the Eduardo_CustCarTable table.

2.In the property sheet for the table, set the PrimaryIndex property on the table to RentalIdx

Parts

So, what are Parts? [From Microsoft - http://msdn.microsoft.com/en-us/library/gg844683.aspx]A Part is a specialized type of control you use to retrieve and show a collection of data. A part specifies how to retrieve the data that appears in the FactBox pane of a form, the preview pane of a list page, or the enhanced preview of a control. You use parts to provide information related to a record that appears in a form…

…To create or modify a part, you use the properties of that part to describe how to retrieve and show data. For example, you use a part property to specify the data source for the part. Typically, you use a query as the data source for a part. You also use properties to specify the data fields that show when the part appears as a FactBox on a form.

Then a FactBox is the collection of data that appears on the form, which is based on a Part.In addition, a FactBox always represents a single part, and if we want to modify a FactBox, we must modify the underlying part.

In AX 2012, a part is defined by using metadata and each part we create extends a common metadata model for parts. Further, one of the best advantages of the Part metadata model is that enables us to create parts that can appear in both the client and Enterprise Portal (EP).

Parts also allow us to represent data through cues in AX 2012. To show a cue in the FactBox pane of a form, you add the cue to a cue group part. A cue group is a type of part that contains one or more cues, and these can be created as a cue group that can appear in forms for both the client and EP, which can be used to add information to a role center page.

In my next and last post about this topic, we will create the user forms needed to display the Auto Rental data. In addition, we will create menu items, and of course a FactBox to display Auto Rental information related to a customer.

So, let’s get to work right away. Let’s create the 3 EDTs and 4 tables. Just note that the naming convention for the entire project’s objects will be as follows:

Eduardo_ObjectName (It is going to look weird, but just change it to whatever you want)

Create the Extended Data Types (EDT):

Steps:

1-Open a new development workspace.

2-In the AOT, expand the Data Dictionary node.

3-Right-click the Extended Data Types node.

4-Select New > String. A new EDT called Type1 is created.

5-Right-click Type1 and select Properties.

6-Modify the property Name to Eduardo_VehicleMakeID.

7-Modify the property Extends to SysGroup.

8-Modify the property Label to Vehicle Make ID.

9-Click Save in the AOT to save your changes.

10-On the Database Synchronization dialog, click Yes. This will take a few minutes to complete.

Next, create the Eduardo_VehicleTypeID and Eduardo_VehicleModelID EDTs by repeating steps 3 to 10. Just remember to change the Label to Vehicle Type ID and Model Type ID.

You AOT should look something like this:

The next step will be to create the tables, fields, indexes and relationships. Let’s create the Eduardo_VehicleTypeTable.

Based on our simple DB diagram, the Eduardo_VehicleTypeTable should have two fields; (1) Vehicle Type Id, and (2) Name.

Steps:

1.In the AOT, expand the Data Dictionary node.

2.Right-click the Tables node and select New Table. A new Table called Table1 is created.

3.Right-click Table1 and select Properties.

4.Modify the property Name to Eduardo_VehicleTypeTable.

5.Modify the property Label to Vehicle Types.

6.Press Ctrl-D to open another AOT.

7.Expand the Data Dictionary node.

8.Expand the Extended Data Types node.

9.Locate the Eduardo_VehicleTypeID EDT.

10.Drag the Eduardo_VehicleTypeID EDT to the Fields node of the Eduardo_VehicleTypeTable table. A new field called Eduardo_VehicleTypeID is created.

11.Right-click the Eduardo_VehicleTypeID field and click Properties.

12.Note that the Extended Data type for this field is set to Eduardo_VehicleTypeID.

13.In the Name property, set the name of the field to VehicleTypeID.

14.Locate the Name EDT in the second AOT.

15.Drag the Name EDT to the Fields node of the Eduardo_VehicleTypeTable. A new field called Name is created.

16.Save your changes to the table. When changes to a table are saved, Microsoft Dynamics AX automatically synchronizes the changes made within its Data Dictionary with SQL: this ensures that the definitions for the tables remain consistent at all times.

Now, follow steps 2-5 for the Eduardo_VehicleMakeTable.

Before we continue with the Eduardo_VehicleModelTable, I would like to talk about creating relationships directly on an EDTinstead of creating the relationship manually on a table.

First, by creating a relationship on an EDT instead of a table, you can set a relationship with a table that can be reuse many times without having to create the same relationship over and over. Second, we can simplify the creating a new field, a new index, and a relationship steps into one simple drag-and-drop action.

NOTE: In Microsoft Dynamics AX 2012, relations can no longer be created under extended data type (EDT) nodes in the Application Object Tree (AOT). Relations that are defined under EDT nodes are still effective, but in a future release they will be obsolete and deleted.

Now do steps 1 to 10 to create a relationship on the Eduardo_VehicleMakeID EDT.

This should look like this:

The next step is to create the Eduardo_VehicleModelsTable. This table will have 5 fields, which three will be the EDT we created earlier.

Steps:

1.In the AOT, expand the Data Dictionary node.

2.Right-click the Tables node and select New Table. A new Table called Table1 is created.

3.Right-click Table1 and select Properties.

4.Modify the property Name to Eduardo_VehicleModelsTable.

5.Modify the property Label to Vehicle Models.

6.Press Ctrl-D to open another AOT.

7.Expand the Data Dictionary node.

8.Expand the Extended Data Types node.

9.Locate the Eduardo_VehicleModelID EDT.

10.Drag the Eduardo_VehicleModelID EDT to the field node on the Eduardo_VehicleModelsTable.

11.Change the name to VehicleModelID.

12.Locate the Eduardo_VehicleTypeID EDT.

13.Drag the VehicleTypeID EDT to the field node on the Eduardo_VehicleModelsTable.

14.When prompted to add the Foreign Key relation from the EDT, click Yes. This will automatically create the relation between the Eduardo_VehicleTypeTable table and the Eduardo_VehicleModelsTable.

15.Locate the Eduardo_VehicleMakeID EDT.

16.Drag the Eduardo_VehicleMakeID EDT to the field node on the Eduardo_VehicleModelsTable.

17.When prompted to add the Foreign Key relation from the EDT, click Yes. This will automatically create the relation between the Eduardo_VehicleMakeTable table and the Eduardo_VehicleModelsTable.

18.Locate the NoYesID EDT in the second AOT.

19.Drag the NoYesID EDT to the Fields node of the Eduardo_VehicleModelsTable. A new field called NoYesID is created.

20.Change the name to Status.

21.Locate the Description EDT in the second AOT.

22.Drag the Description EDT to the Fields node of the Eduardo_VehicleModelsTable. A new field called Description is created.

NOTE: In addition to the relationships, two new indexes and two new fields were created as well. You may change the name of these fields to make them meaningful to you.

The Eduardo_VehicleModelsTable should look something like this:

Now that the Eduardo_VehicleModelsTable has been created along with the fields, indexes and relationships, the next step is to create the relationship on the Eduardo_VehicleModelID EDT.

Ah! You might ask yourself, why didn’t we create the relationship for this EDT earlier? The reason we didn’t do this earlier was because an extra relationship would have been created if the Eduardo_VehicleModelIDEDT had a relationship before creating the Eduardo_VehicleModelsTable.VehicleModelID.

So far so good, I hope you are still with me. Now we need to create a table that will hold customer and car information data. Then this table will be our main data source on a custom form we will create later in this post.

Steps:

1.In the AOT, expand the Data Dictionary node.

2.Right-click the Tables node and select New Table. A new Table called Table1 is created.

3.Right-click Table1 and select Properties.

4.Modify the property Name to Eduardo_CustCarTable.

5.Modify the property Label to Customer Cars.

6.Drag the Integer EDT to the field node on the Eduardo_CustCarTable.

7.Change the name to RentalID.

8.Press Ctrl-D to open another AOT.

9.Expand the Data Dictionary node.

10.Expand the Extended Data Types node.

11.Locate the Eduardo_VehicleModelID EDT.

12.Drag the Eduardo_VehicleModelID EDT to the field node on the Eduardo_CustCarTable.

13.When prompted to add the Foreign Key relation from the EDT, click Yes. This will automatically create the relation between the Eduardo_VehicleMakeTable table and the Eduardo_VehicleModelsTable.

14.Change the name to VehicleModelID.

15.Locate the CustAccount EDT.

16.Drag the CustAccount EDT to the field node on the Eduardo_CustCarTable table.

17.Drag the TransDate EDT to the field node on the Eduardo_CustCarTable table.

18.Change the name to RentalStartDate.

19.Drag the TransDate EDT to the field node on the Eduardo_CustCarTable table.

20.Change the name to RentalEndDate.

The Eduardo_CustCarTable should look like this:

At this point you should fill both the Eduardo_VehicleTypeTable and the Eduardo_VehicleMakeTable [tables] with some data. Once you do that, open the Eduardo_VehicleModelsTable and add some data about the vehicles. You should be able to select a Vehicle Make from the VehicleMakeID field and a Vehicle Type from the VehicleTypeID field.

Vehicle Make

Vehicle Type

NOTE: If for some reason one of your relationships is not working (you'll know because you won't be able to select either a vehicle make or vehicle type from the fields), you will have to delete the relationship that is not working and create it manually. Also make sure that your indexes names are correct.

In my next post we will create a primary index for a table and dive deeper into Form Parts.