0% found this document useful (0 votes)
14 views

Dual Write_005 - Create a custom entity in F&O and then use it with Dual-write to sync data to Dataverse

Uploaded by

babu thum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Dual Write_005 - Create a custom entity in F&O and then use it with Dual-write to sync data to Dataverse

Uploaded by

babu thum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Sample document with Code samples:

Create a custom entity in Dynamics 365 Finance and Operations


and use it with Dual-write to Sync data to Dataverse (CE/CRM)

Last Updated: 11 January 2023

1
1. Overview ....................................................................................................................................................................... 3
2. Lab Prerequisites ........................................................................................................................................................... 3
3. Create a Custom Table, Form and Data entity in Visual studio .................................................................................... 3
3.1 Create a custom model. .......................................................................................................................................... 3
3.2 Create Extended Data Types ................................................................................................................................... 7
3.3 Create a table ........................................................................................................................................................ 12
3.4 Create a form ........................................................................................................................................................ 17
3.5 Create Staging Table /Data Entity ......................................................................................................................... 22
3.6 Create a Display menu item .................................................................................................................................. 25
3.7 Create an extension of CommonMenu ................................................................................................................. 26
3.8 Full Build and DB Syncronize the Model ............................................................................................................... 28
Step 3.9 Fill Data in the Book Table form ................................................................................................................... 30
4.0 Create custom Entity in CE ........................................................................................................................................ 31
4.1 Create a custom table in Dataverse ................................................................................................................ 31
4.2 Create Table Columns ........................................................................................................................................... 34
4.3 Create a custom table map for Book table entity ................................................................................................. 36
4.4 Run Initial Sync on Book table entity map ............................................................................................................ 38
4.5 Test Live Sync for Book table entity map: F&O -> Dataverse ............................................................................... 39
4.6 Test Live Sync for Book table entity map: Dataverse -> F&O ............................................................................... 41

2
1. Overview
The scope of this lab is to provide step-by step instructions that help to get familiar with how create a custom entity
in D365FO and consume it in Dual Write. It assumes the user has basic familiarity with AOT and creating D365FO
objects in visual studio.

2. Lab Prerequisites
- A dev/test environment deployed from LCS creating a Dynamics 365 Finance and Operations Cloud hosted
environment (CHE) with Power Platform using your own Test/Microsoft 365developer tenant admin account.

Use one of the following links to create a test environment

https://supportability.visualstudio.com/DynamicsFO/_wiki/wikis/Dynamics%20FO/767304/Labs

https://supportability.visualstudio.com/DynamicsFO/_wiki/wikis/Dynamics%20FO/656962/Build-your-own-Cloud-
Hosted-Environment-(CHE)-with-Power-Platform-for-testing-and-development

- Dual-write should be setup with at least one legal entity like USMF

3. Create a Custom Table, Form and Data entity in Visual studio

3.1 Create a custom model.

(a) RDP connect to development machine

(b) Open Visual Studio 2019 and above as Administrator (whenever you launch Visual studio use the Administrator
mode)

(c) Create a custom model from Dynamics 365 > Model management > Create Model:

3
(d) Enter the details below or any other naming details you wish and press Next

(e) Select Create new package radio button and then click Next

4
(f) Select the below checked marked referenced packages and click Next

(g) In Summary page, keep the default settings and click Next

5
(h) Edit the following Project name and Solution name and click “Create”

(i) The result should be like the below:

6
3.2 Create Extended Data Types

Create 4 extended data types as follows:


(a)
(i) To create an object right click on the project name DWExtensionProject, in the Solution Explorer and
click on Add > EDT > String
Name: BookId

Size: 10

Label: Book number

(ii) Right click on the project name DWExtensionProject, in the Solution Explorer and
click on Add > EDT > String
Name: BookTitle

Set properties:

Size: 30

Label: Book title

7
(b) Right click on the project name DWExtensionProject, in Solution Explorer and click on Add > EDT >
Integer
Name: AvailableNumber
Set property:
Label: Available number

8
(c)
(i) Right click on the project name ‘DWExtensionProject’, in Solution Explorer and click on Add > EDT >
Enum > select Base Enum template
Name: BookGenre
Set properties - Label: Book genre

(ii) Create and add following 4 Element Values by right clicking BookGenre, in middle pane, and select New Element:

Name: History, Label: History

Name: Poetry, Label: Poetry

Name: Fiction, Label: Fiction

Name: NonFiction, Label: Non-Fiction

9
(d) Right click on the project name DWExtensionProject, in Solution Explorer and click on Add > EDT >
Enum
Create an EDT Of type Enum based on the above BaseEnum. Set the following properties:

Name: BookGenreEDT

EnumType: GookGenre

Label: Book genre

(e) Right click on the project name ‘DWExtensionProject’, in Solution Explorer and click on Add > EDT >
Date > select EDT Date template
Name: AvailableDate

Label: Available from date

10
- click Save all in Visual studio

11
3.3 Create a table
(a) Right click on the project name ‘DWExtensionProject’, in Solution Explorer, and click on Add > Table…
Name: BookTable
Set properties - Label: Book table

(b) Add all created Extended Data types in previous step as table fields:

Select all the fields from the solution explorer and drop it on the Fields node in the middle pane

(c) Right click on Field groups > New Group


(i) In the properties window set the name of the Group to BookTableFieldGroup

12
(ii) Drag and drop all the five fields on the BookTableFieldGroup

(iii) It should now look like this

(iv) In Visual Studio menu, click on Save All

13
(d) Create two table indexes
(i) Unique Index name: “BookIdIdx”
- Right click on Indexes node and select create a new index.
- Drag and drop the BookId field from under the Fields section on the new index.

- Set below highlighted properties values for the new index.

14
(ii) Non-unique index name: BookTitleIdx
- Right click on Indexes and create a new index.
- Drag and drop the BookTitle field from under Fields section on to the new index.

- Set below highlighted properties values for this new index.

15
(e) Select the BookTable in middle pane and in the properties section
Set “Title field1”= BookId
Set “Title field2”= BookTitle

- click Save all button in Visual studio

16
3.4 Create a form
(a) Right click on the project name DWExtensionProject, in Solution Explorer, and click on Add > Form…
Name: BookTableForm

(b) Add BookTable table as form datasource.


Drag and drop BookTable on the Data sources node.

- Select BookTable datasource and set/verify below highlighted properties values

17
(c) Create a Custom Design pattern
(i) In the middle pane, right click on Design | Pattern: <unspecified>

Click on Apply Pattern > Custom

- In the properties, set below highlighted values

(ii) Create an ActionPane


Right click on Design|Pattern: Custom and select New > Action Pane

- Set below highlighted property values

18
(iii) Right click on Design|Pattern: Custom and select New > QuickFilter

- Set below highlighted properties values for the QuickFilter

(iv) Right click on Design|Pattern: Custom and select New > Grid

19
- Set below highlighted properties values for the Grid

(v) Create a field group under Grid control


- On the left-hand side under BookTableForm expand Data sources > Book Table > Field groups

- Drag and drop the BookTableFieldGroup on to the right side on top of FormGridControl(Grid)
- This will create a BookTableFieldGroup (Group). Verify the properties of this new group looks the same
as below:

20
(iv) Notice the group also shows all the fields. Click on Save all button in Visual studio menu, to save your progress

21
3.5 Create Staging Table /Data Entity
(a) Find BookTable table in the project, then right click and select Open

(b) Right click on the name BookTable > Select Add-Ins > Create data entity

(c) Wait for process to complete. The following objects will be created in your data project

(d) Right click on BookTableEntity and select Open


Set the following property values:

22
23
(e) Right click on BookTableEntity and select Open
Set/Verify the following property values:

24
3.6 Create a Display menu item
Create a Display menu Item so that we can view the form in D365FO
(a) Right click on the project name ‘DWExtensionProject’, in Solution Explorer, and click on Add > New
Item…

(i) In the Add New Item form, from Left hand side under Dynamics 365 Items select User Interface
(ii) In the middle pane select Display Menu Item
(iii) Fill Name: BookTableMenuItem
(iv) Click on Add
(v) Once the BookTableMenUItem is created, select it in the middle pane, and then fill in the
Properties on bottom-left as follows:

25
3.7 Create an extension of CommonMenu
(a) In the Application Explorer search for CommonMenu

(b) Right click on CommonMenu shown under the AOT and click on Create extension..
Notice in the Solution Explorer it has created a new object CommonMenu.DWExtensionModel

(c) Doublick on CommonMenu.DWExtensionModel in the solution explorer to open it


Then in the middle pane expand Common submenu and drag and drop the BookTableMenuItem item
from the solution explorer on to the Common menu

26
(d) Click on Save all in the Visual studio menu

27
3.8 Full Build and DB Syncronize the Model
(i) From the Visual Studio Menu, go to menu Extensions > Dynamics 365 and select Build models…

(ii) Under the Packages tab, search and find DWExtensionModel, and select the check box next to it.

28
(iii) Select the Options tab, make the following selections underneath it and then press Build button.

(iv) The build will take a while. Ensure you get no errors. Ignore all the warnings.

29
Step 3.9 Fill Data in the Book Table form

(i) Log in to Dynamics 365 FO. Go to Modules > Common > Common. Verify that it has created the Book
table form menu item:

(ii) Click on it to open the form. Click on Edit in the menu and then create a couple of records as shown
below, and click on Save just to ensure the form is functional.

30
4.0 Create custom Entity in CE

4.1 Create a custom table in Dataverse

First we will create a custom table in Dataverse that has similar fields as BookTable that we can copy the
data to.
(i) Log on to https://make.powerapps.com
Make sure to select the right environment you are using example:

(ii) Expand Dataverse node and select Tables

(iii) Click on +New table. A side form titled New form opens. Under the Properties tab enter the
following values:

31
(iv) Next click on Primary column and enter the below details:

32
(v) Click on Advanced options, and review the below default options without making any changes:

(vi) Click on Save

33
4.2 Create Table Columns

(i) Dataverse > Tables > FOBookTable


(ii) Click +New and select Column

(ii) Create 6 new Columns as below. Save each column before creating the next column.
1 2 3 4 5

34
(iii) Create a final new Column for Company as below and click Save

(iv) The final table should look like this:

(v) Click on Advanced > Publish table. Wait till you see

35
4.3 Create a custom table map for Book table entity
(i) Log back into D365FO
(ii) Go to Data Management workspace > Dual write
(iii) Click on Add table map
(iv) A side form opens with title Add table. Fill in the below fields:

- Click on Save
(v) For the new created table mapping, add following 5 bi-directional fields

36
Please note: The DATAVERSE fields prefix on your system may have a different value then what you see.
The fields on my system start with 'cr944_'

(vi) Click on root Dual-write and then click on Integration key menu

(vii) Then click on Integration key tab

(viii) Find FOBookTable and ensure It has the following keys

- After adding the keys click on Save

37
4.4 Run Initial Sync on Book table entity map

- Open Dual write


- Click on Search and find “Book table entity”
- Open Book table entity map
- Click on Refresh tables menu
- Once refresh completes, click on Run, and select Initial Sync check box

- And click on Run at the bottom of the page


- Wait a few minutes and check the Initial sync details menu till it is complete.
- The map should now be in Running status:

38
4.5 Test Live Sync for Book table entity map: F&O -> Dataverse

(i) Log on to FnO, from the UI front end, find the form menu under the following sub-menu:

(ii) Open the form on the legal entity that is setup to sync with DATAVERSE
- E.g on my DATAVERSE I am only syncing records from company USMF
- Hence I switched to USMF company and then opened the form
- - and then create a record as shown below (Only for testing purposes)

39
(iii) Log on to https://make.powerapps.com
- Connect to the correct Environment.
- Then go to Dataverse > Tables > FOBookTable
- Then verify the record got created:

40
4.6 Test Live Sync for Book table entity map: Dataverse -> F&O

(i) Log on to https://make.powerapps.com


- Connect to the correct Environment.
- Then go to Dataverse > Tables > FOBookTable

(ii) On the FoBookTable, click on Edit button and then select Edit

(iii) Click on +New row

- Add the Company field if not visible


- Then enter the highlighted values
- Finally click the mouse on the last row and it will save the data or switch rows.
- Then click on <-Back menu button

41
(vi) You will see the new record you created on the FOBookTable

(vii) Next log into F&O, USMF company.


- Go to Common > Common > BookTable form
- Notice you can see the record you created in Dataverse

If you got this far then congratulate yourselves! This completes the sample document with code samples to
demonstrate creating a custom entity and using it with Dual-write to sync data.

This document was edited whilst following the steps. If you find any errors please report them to:
MansourM and AnupShah

42
---------------------------------------
Disclaimer:
This sample document and sample code examples is for illustration purposes only. Microsoft disclaims all warranties
and conditions with regards to use of the sample document and sample code for other purposes. Microsoft shall not,
at any time, be liable for any special, direct, indirect, or consequential damages, whether in an action of contract,
negligence or other action arising out of or in connection with the use or performance of the document and sample
code examples. Nothing herein should be construed as constituting any kind of warranty.
-----------------------------------

43

You might also like