You can see them all of Dynamics AX. Fact boxes are a great way to show information relating to the current record that you are in, without cluttering up the main data in the form. Also you can pick and choose if you want to see the information as well. But you don’t have to settle for the fact boxes that are delivered with Dynamics AX, you can easily create some more of your own if you don’t mind getting your hands a little dirty with a little coding.
What a great way to Gamify your customers.
How To Do It…
Setting Up Your Fact Box Development Project
The first thing that you will want to do is to create a development for your fact box project so that you can keep all of your development packaged up in a nice little box.
- Start off by finding the form that you want to add the fact box to. In this example, the Customers form will be a great place to start.
- Then right-mouse-click on the main form and select the Personalize option from the context menu bar.
- When the Personalization dialog box is displayed, switch to the Information tab and you will see the actual Form Name. Click on the Edit button to the right pof the Form Name field.
- This will open up the AOT development environment with the form definition already selected.
- In the menu bar, click on the Projects button to open up the Projects Explorer window.
- Right-mouse-click on the Private projects folder and select the New menu item and then the Project option.
- This will create a new Project for you.
- Double-click on the Project name and you will be able to rename it to something that is a little more descriptive.
- Now tile the two windows so that you can see both the form and the project window.
- Grab the CustTable form and drag it over to the Project to add it to your project package.
- Now you can close down the form window and start focusing on the project itself.
Creating The Fact Box Form
Now that we have our project set up we can start working on building the fact box. The first thing that we need to do is create a form that we will use to display our button in.
- To do this, right-mouse-click on the project folder and then from the New submenu select the Form menu item.
- This will create a new form for you.
- Double-click on the form so that you can rename it to something that is a little more suited to the project.
- The trick with the Fact boxes is that they need to have a data source associated with them that is linked back to the parent form so that we can use it to craft the data for the badges. To do this, click on the DataSources folder within the form and select the New DataSource option.
- When the new DataSource is created, select it and then within the Properties panel you will be able to give your Then from the Table dropdown select the table that you want to use as a link. In this case we want the CustTable.
- Then change the OnlyFetchActive property to be Yes. This will tell the form to grab the currently active record from the parent table.
Creating The Fact Box Form Part
Now that we have the Form that we will use for the Fact Box we need to wrap it within a Form Part so that Dynamics AX will allow us to use it as a Fact Box.
- To do this, right-mouse-click on the projects top level and select the New submenu, and then select the Parts submenu
so that you can select the Form Part menu item.
- This will create a new FormPart for you.
- Double-click on the FormPart so that you can rename it to a friendlier name and also update the Caption property.
- From the Form property click on the dropdown list and select the form that you just created.
- After you have done that you can continue to the next step.
Creating The Fact Box Menu Item
Once we have a FormPart, we need to create a menu item that points to it so that we can add it to our main form.
- To do this, right-mouse-click on the projects top level and select the New submenu, and then select the Menu Item submenu and then select the Display menu item.
- This will create a new menu item for you.
- Within the Properties of the menu item, set the Name and Label fields to something a little friendlier.
- Then change the ObjectType to FormPart.
- That will allow you to select your new FormPart that you just created from the Object property dropdown list.
- After you have selected the FormPart you are done with this step.
Adding The Form Part To The Main Form
Now we can add fact box to our main form.
- To do this, expand out the main form, and then expand out the Parts folder. You will see all of the fact boxes that have already been added to the form.
- Right-mouse-click on the Parts node and select the New Part Reference menu item.
- This will add a new Part to your form.
- Within the Properties for the Part, change the Name property to a better name.
- Then select the new Menu Item that you created from the MenuItemName dropdown list,
- The DataSource should automatically default in as the main table (in this case the CustTable) so you just need to select the SelfLink option from the DataSourceRelation dropdown to tell it to link with the form datasource.
- All done.
Viewing The Fact Box
Now we have created enough to see part of the project in action.
- When you re-open up the CustTable form you should see a new Fact Box is shown.
How cool is that!
Adding The Customer Achievement Charms
Now that we have the Fact Box we can start populating it with some cool charms and badges.
- To do this expand out the Fact Box Form that you initially created, expand out the Designs group and right-mouse-click on the Design node. Select the New Control menu item and select the Button menu item.
- This will create a new Button for you which is a great way to show images.
- Change the Name property on the button to a name that is easier to reference.
- Then change the ButtonDisplay property to Image Only so that it will show just a picture.
- Now click on the … button to the right of the NormalImage property and select the image that you want to show when the badge is turned on.
- This will add the path to the image into the property field.
- Now click on the … button to the right of the DisabledImage property field and select the disabled image.
- You may also want to set the Enabled property to be No by default.
- To make the button look less like a button, change the Border property to None.
- And also set the BackStyle property to Transparent.
- Now you can save your project by clicking on the Save icon in the tool bar.
- If you take a peek at the Customer form you will now see that the image is shown.
Adding Logic To Manage The Badge
There is only one step left to go, and that is to add a little logic to the fact box so that it starts updating based on the data that is in the main form.
- To do this we need to write some code that is triggered off the data changing. An easy place to do this is the CustTable datasource, so expand out the Fact Box Form, expand the DataSources, and then the CustTable datasource that you originally added.
- Right-mouse-click on the Methods node and select the Override Method option and then select the Active method.
- This will open up the X++ code editor for you with the default methods code.
Then add the following code to the method
count(RecId) From salesTable
where salesTable.CustAccount == CustTable.AccountNum;
recCount = salesTable.RecId;
element.design().controlName(“TopCustomerBadge”).enabled(recCount > 1);
- You can now close the editor and save the project.
- Now when you browse to the customers, if they don’t have any sales orders then the badge is disabled.
- When you do find a customer that has some sales associated with it then it starts to light up.
If information is power, then Fact Boxes are the currency when it comes to Dynamics AX. There are so many examples that we can think of where an additional Fact Box would be useful to display another snippet of information that you may need to do your job just a little quicker. By using Fact Boxes, the users can also pick and choose what information they see without cluttering up the main forms or adding too much extra noise to the application.
Although they do involve a little bit of code, they are really not hard to create so what are you waiting for?