Power Platform – Creating Relationships between Entities and create a Canvas App using Common Data Service (CDS)
We discussed in our last article about Creating Entities in Common Data Service (CDS) – https://knowledge-junction.com/2020/07/02/power-platform-creating-entities-in-common-data-servicecds/ . Now let’s begin with relationships and create a canvas app using CDS.
What is mean by Relationships?
Entity records can be associates with records of other entity or same entity. In simple words one entity data relates (relation) to other entity data
For example we have Team Leads entity and Developers entity where Developers entity has lookup relationship to the Team Leads entity to show which developer work under which team lead person. You can use a lookup field to show data from the Team Leads entity.
We can create several types of relationships from one entity to another (or between an entity and itself). Each entity can have a relationship with more than one entity, and each entity can have more than one relationship to another entity.
There are some relationships types are:-
1. One-to-many – In this type of relationship, each record in entity A can match only one record in entity B but each record in entity B can match more than one record in entity A. For example single team lead work with more than one developer.
2. Many-to-one – In this type of relationship, each record in entity A can match many record in entity B but entity B can match only one record in entity A. For example a many project handle by one company.
3. Many-to-many – In this type of relationship, each record in entity A can match more than one record in entity B and vice versa. For example, students attend many classes, and each class can have multiple students.
Creating relationship for entity
- Now open https://make.powerapps.com on left navigation pane select Data -> Entities
- Used existing or create new entity as we discussed in previous article https://knowledge-junction.com/2020/07/02/power-platform-creating-entities-in-common-data-servicecds/ .
- Select your created entity from list and click on Relationships tab.
- Click on “+ Add relationship”
5. Now select type of relationship from drop down, we are selecting + Many -to-one.
6. Now select Related (One) -> Account from list, you can select any entity from drop down which we want to lookup relationship and click on Done.
7. When we done with this all steps then Account field with data type lookup automatically added to the list of fields.
We are done with creating relationships now time to create a Canvas App.
Creating Canvas App using Common Data Service
- Now open https://make.powerapps.com or from left navigation pane select Home.
- Select Start from data-> Common Data Service.
- Connection window opens then select “+ New connection”.
4. Select Common Data Service from My connections and click on Create.
5. Choose a table or entity from list and click on Connect. We are going to select our created entity as we see in previous article https://knowledge-junction.com/2020/07/02/power-platform-creating-entities-in-common-data-servicecds/.
6. Welcome window pop up please skip it and PowerApps studio page opens.
7. There are three screens as we can see on left navigation pane Tree View-> Screens tab.
8. On the home tab you can see New Screen select the down arrow and select List from drop down list, we are adding list.
9. Now screen is added with several default controls such as search and gallery control which covers all screens under search box.
10. Click on Screen1-> BrowseGallery2 and select data source as table name or entity name or on your right – hand pane of BrowseGallery2 Properties tab select Data source as a table name or entity then select Layout and from drop down list select title, subtitle and body.
11. Select Fields -> Edit and add data as Body1 -> Address , Subtitle1 -> MobileNo and Title1 -> EmpName.
12. We will delete and rename form by clicking on ellipsis(…) rename of Screen1 to ViewScreen and EditScreen1 to EditScreen .
13. On Record ViewScreen select circular-arrow icon set the OnSelect property to formula Refresh(Employees). When user selects this icon, the data from Employees is refreshed from the data.
14. Now select Plus “+” icon and set OnSelect property to formula “NewForm(EditScreen);Navigate(EditScreen,ScreenTransition.None)”. When user click on plus sign Edit Form opens and we will add new records in data. Change label [Title] to Employees of ViewScreen.
15. Select right side arrow of records in the gallery and set the OnSelect property by this formula “EditForm(EditForm1); Navigate(EditScreen, ScreenTransition.None)”.When user click on arrow Edit Form opens in which user edit, update and delete records.
16. Select EditForm from left navigation pane.
17. Now on right hand pane select Properties-> Edit fields and click on +Add field and check all columns from drop down list.
18. Select cross sign of the page near left side to the page title and set OnSelect Property by this formula ResetForm(EditForm1);Navigate(ViewScreen,ScreenTransition.None). When user click on cross sign its redirected to ViewScreen page.
19. Now select on checkmark sign near right side to title and set OnSelect property by this function SubmitForm(EditForm1);Navigate(ViewScreen,ScreenTransition.None). When user click on sign the changes made by user is saved and redirected to ViewScreen page.
20. For Testing the app press the play button.
21. Now we will Save , update and delete records from Common Data Service using canvas app from PowerApp.
Thanks for reading. If it’s worth at least reading once, kindly like and share. STAY SAFE STAY HEALTHY.