In the previous article, I explained what Extended Data Types in D365 is and how to create Extended Data Types. In this article, I will explain how to create a table in Dynamics 365 FO. As we know tables are the core objects used to store data in Microsoft Dynamics 365. In Dynamics 365 FO before creating a form we need to create the tables first. By using visual studio, it is very easy to create a table.
In Dynamics 365 FO, you can use primitive data types or
Extended data types for adding fields to the table. Before creating a new
Extended data type (EDTs), you should check whether the EDT is already existing
in the system, if already exists in the system, you can re-use it. Another
important thing to remember while creating a table is, don’t forget to index
the table to enhance its performance. Also in professional development, you can
create field groups to organize your work and use these field groups in the design of
forms and reports, etc.
So, in this article, I will only show you how to create a
simple table in d365 fo, in the next articles I will show you how to set
indexes and how to set field groups on a table and how to create a relation to
another table.
So, in this article, we will go through the following steps,
- Â Â Â Â Â Â Create a D365 Project.
- Â Â Â Â Â Create a table.
- Â Â Â Â Â Add new fields to the Table.
If you are a beginner or a learner, you can use Microsoft’slearning platform for practicing D365 FO scenarios. There you can access both
the technical and functional environments for practicing more.
In this article, we are creating a table with the name TblEmployee
with three fields as shown below.
After creating the table TblEmployee, it is very important to
add fields to the table as per our requirement, so here we are adding three
fields EmpId, EmpName, and Gender. For the field EmpId, I use data
type EDT int and for the field EmpName, I use two EDT String,
for the field Gender I use Enum as the data type. Â You can refer above table structure for any
doubts.
For this open your ‘Visual Studio’. Right-click on Visual
Studio and select ‘run as administrator’. It is important when doing
development that you run Visual Studio as an administrator. Then follow the steps.
1. Create a D365 Project
Select File>New>Project. In the dialog that opens,
select Dynamics 365 on the left-hand side. Then select Finance Operations as
the project type.
Next, right-click on your project, and select Properties. In
the dialog that opens, set the ‘Model’ to your custom model, if you have already
created a model, you can re-use the model. Here I used the Fleet Management
model and Also set the ‘Synchronize Database on Build’ property to True.
This is needed when creating or modifying tables so that the changes you make in
Visual Studio get synched to the actual SQL Server Database.
2. Create a Table
Next, I will show you how to create a table. Right-click on
your project and select Add > New Item. In the dialog that opens, select
‘Table’, and provide a name for the table. In my example, I will call my table TblEmployee.
Then press Add button.
You can see the table TblEmployee is created,
3. Add new fields to the Table
As we already discussed, here we are adding three fields EmpId,
EmpName, and Gender. For the field EmpId, I use data type EDT int and for the field EmpName, I use two EDT String, for the field Gender I use Enum
as the data type. You can refer above table structure for any doubts. So, we need
to create two EDTs and Enum Data types.
When you know you are creating a field with a new Extended
Data Type, it is more efficient to create the EDT first, then drag it to your
table. Rather than create the field on the table, create the EDT, then set the
Extended Data Type property on the field. Let’s continue with our example. For
creating EDT for EmpId, Right click on the Visual Studio Project and select
Add>New Item. Select EDT Integer. Set the name to EmpId.
Then click the ‘Add’ button as shown below.
For this,
For creating EDT for EmpName, Right click on the Visual
Studio Project and select Add>New Item. Select EDT String. Set the
name to EmpName. Then click the ‘Add’ button as shown below.
For the field Gender, we do not need to create a new Enum Data
type, because Gender Enum is a standard Data type, so you can reuse it,
You can assign EDTs to a table field in two different ways,
first, you can drag and drop the EDT into the ‘Fields’ node on the table
designer, and it will automatically create a field with the assigned type. Another
way is creating a field with primitive data types and right-clicking on the field
and selecting ‘Properties’. Set the Extended Data Type property to the already
created EDT.
Right-click on the EDT and select Properties. While there
are many properties we can set on an Extended Data Type, the main ones for a
string are Label, Help Text, and String Size. So, you can change these
properties as per your requirements.
The next step is Open the TblEmployee table
designer by double-clicking on it. Drag the EDT EmpId into the
‘Fields’ node on the table designer. This will create the field and set the
Extended Data Type Property on the table all in one step. In the same way, we Drag the
EDT EmpName into the ‘Fields’ node on the table designer.
For creating the Gender field, we must Drag the
EDT Gender into the ‘Fields’ node on the table designer as shown in the
below figure.
For this open Application Explorer > AOT > Data Types
> Base Enums > Drag the EDT Gender into the ‘Fields’.
Now our table TblEmployee is ready, after a successful build of the project, this table will be synchronized to your
project, for testing purposes you can use Table Browser, for this Right
click on the Table > Open Table Browser.
Through the next articles, we will also learn how to set indexes and how to set field groups on a table and how to create a relation to another table. If this post is useful for you, try to share this with your friends also. You can explore more tutorials from this blog. Happy coding with D365 Snippets.