In this post, I have used data from the Northwind database that comes with MS Access. It contains a number of tables with relationships. I selected the Customers and Orders table for the example. Following the example, I will explain how to bring a more complex database into the Common Data Service. The first step was to bring in the tables from MS Access by exporting them to Excel and saving them in my OneDrive for Business. In the folloiwng example, I am referring to the Customers table as the Parent and the Orders table as the Child. The Primary key from the Parent is the Foreign key in the Child table. The relationship is One to Many as one customer can have many orders but each order can have only one customer.
Open the entity and examine it. It contains all of the columns now with “Custom” type and many “Standard” type columns that are metadata of the entity. Note that Company has a Primary Name and that in addition to the ID column there is a new column called Customer and it is of the Unique type. This is the GUID column that will be added to the Orders table in the next steps.
Choose the Edit data in Excel and save the resulting file in OneDrive for Business. Upon opening it, you can examine the custom columns as well as the metadata that has been added. In the next steps, you will need this file so remember where it is. This is now the Parent Entity.
Transform the table by eliminating unneeded data columns. Then select New Source in the upper right side of the screen and open the Excel file that was created from the entity.
Examine the Parent table and amongst the metadata is a column Customers that contains the GUID generated by PowerApps for the Parent entity. Note the Queries column on the left side of the screen now contains both tables.
Other than the Foreign key field this is the only column needed so remove all of the other ones using Choose columns. Then switch back to the orders query by selecting it in the upper left side column.
In the Orders query select the merge queries option and select the Customers query for the merge. Merge by selecting the Foreign key in Orders and the Primary key in Customers and select OK.
Select it and select the Customer column only.
Now open the Child entity (orders) in Excel. Note that two new empty columns were created by adding the Lookup column. The first will be on the left side of the table and will contain the name of the Lookup field “CustomerLU” followed by “(Lookup)”. Ignore it and find the GUID column that was added in the last step and copy it.
Locate the empty CustomerLU field amongst the metadata columns on the right side of the table. Paste the GUIDs into this column and Publish the table from the lower right hand side of the screen.
The Lookup field is now populated and since the Many to One relationship is now established and populated, additional data entered using this field will automatically be linked by the relationship. The Excel file can now be closed.
The process for recreating a more complex database using CDS from external sources uses the steps above. First, examine the external database for One to Many relationships. Start with Tables that only include the One side and import these first. These will be Lookup Tables for the most part. Then select tables that have lookup fields but are Parent tables to other Child tables. Finally bring in the lowest level Child tables. In my experience, this has been a very cumbersome process but appears to be the only way for importing a database with relationships as CDS uses its own GUIDs to define the relationships between entities.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.