Practice Lab 5 – External data

In this lab you will add an external data source.

What you will learn

  • How to add a SharePoint list to your canvas app
  • How to use collections
  • How to use Patch
  • How to use Office365Users connector

High-level lab steps

  • Create a SharePoint list for Bookings
  • Add the SharePoint list as a gallery
  • Store selected records from a gallery
  • Use Patch to set the decision for a booking request
  • Use Office365User connector to display the user’s details.

Prerequisites

  • Must have completed Lab 4: Build the UI

Detailed steps

Exercise 1 – Create SharePoint list

Task 1.1 Create a SharePoint site

  1. In the Power Apps maker portal, https://make.powerapps.com select the App launcher in the top left of the browser window and then select SharePoint.

  2. If the Welcome to SharePoint Start Page popup dialog is displayed, select to close the dialog.

  3. In SharePoint, select + Create site.

  4. Select Team site, select Standard team template, and select Use template.

  5. Enter Pet boarding for Site name and select Next.

  6. Select Create site.

  7. Select Finish.

  8. If the Start designing your site pop-up dialog is displayed, close the dialog.

Task 1.2 Create a SharePoint list

  1. In the SharePoint site, select + New and then select List.

    Screenshot of new SharePoint list.

  2. Select List under Create from blank.

  3. Enter Bookings for Name and select Create.

  4. Select + Add column, select Text, and select Next.

  5. In the Create a column pane, enter or select the following values:

    1. Name: Pet Name
    2. Data type: Single line of text
  6. Select Save.

  7. Select + Add column, select Text, and select Next.

  8. In the Create a column pane, enter or select the following values:

    1. Name: Owner Name
    2. Data type: Single line of text
  9. Select Save.

  10. Select + Add column, select Date and time, and select Next.

  11. In the Create a column pane, enter or select the following values:

    1. Name: Start Date
    2. Data type: Date and time
  12. Select Save.

  13. Select + Add column, select Date and time, and select Next.

  14. In the Create a column pane, enter or select the following values:

    1. Name: End Date
    2. Data type: Date and time
  15. Select Save.

  16. Copy the first part of the URL of the SharePoint site, for example https://m365x99999999.sharepoint.com/sites/Petboarding/

Exercise 2 – Add SharePoint list to canvas app

Task 2.1 - Edit the app

  1. Navigate to the Power Apps Maker portal https://make.powerapps.com

  2. Make sure you are in the Dev One environment.

  3. Select the Apps tab from the left navigation menu.

  4. Select the Booking Request app, select the Commands (), and select Edit > Edit in new tab.

Task 2.2 - Add SharePoint as a data source

  1. In the app authoring menu, select Data.

  2. Select the drop-down caret next to Add data and enter SharePoint in Search.

    Screenshot of select SharePoint as data source.

  3. Select SharePoint.

  4. Select Connect directly (cloud services) and select Connect.

  5. Enter the URL of the SharePoint site you created earlier in this lab.

    Screenshot of connect to SharePoint site.

  6. Select Connect.

  7. Select Bookings.

    Screenshot of connect to SharePoint list.

  8. Select Connect.

  1. In the app authoring menu, select Insert (+).

  2. Select Vertical gallery.

  3. Select Bookings for data source.

  4. Select Title and subtitle for Layout.

  5. Select 6 selected next to Fields

  6. Select Pet Name for Title3.

  7. Select Start Date for Subtitle3.

  8. Close the Data pane.

  9. In the app authoring menu, select Tree view.

  10. Rename the gallery to BookingList.

  11. Set the properties of the gallery in the formula bar as follows:

    1. X=1000
    2. Y=80
    3. Height=575
    4. Width=250

Exercise 3 – Collections

Task 3.1 Create Collection

  1. In the app authoring menu, select Tree view.

  2. Expand BookingRequestList.

  3. Select NextArrow.

  4. Set the OnSelect property of NextArrow in the formula bar to:

     Collect(colRequests, ThisItem)
    
  5. In the app authoring menu, select Tree view.

  6. Select the App object.

  7. Set the OnStart property in the formula bar to:

     Clear(colRequests)
    

Exercise 4 – Patch

Task 4.1 Decline booking request

  1. In the app authoring menu, select Tree view.

  2. Select BookingRequestList.

  3. Select the pencil icon in the top-left of the gallery control.

    Screenshot of editing the gallery.

  4. In the app authoring menu, select Insert (+).

  5. Expand Icons.

  6. Select Blocked. The icon will be added to each row in the gallery.

  7. Set the properties of the icon in the formula bar as follows:

    1. X=150
    2. Y=40
    3. Height=30
    4. Width=30

    Screenshot of editing the gallery.

  8. In the app authoring menu, select Tree view.

  9. Rename the icon to DeclineIcon.

  10. Set the OnSelect property of DeclineIcon in the formula bar to:

     Patch('Booking Requests', ThisItem, {Decision: 'Decision (Booking Requests)'.Declined})
    

Exercise 5 – Office 365 Users

Task 5.1 Add Office 365 Users as a data source

  1. In the app authoring menu, select Data.

  2. Select the drop-down caret next to Add data and enter Office 365 in Search.

  3. Select Office 365 Users.

  4. Select Connect.

Task 5.2 Display the user’s country

  1. Select outside of the gallery on the blank canvas, or select the MainScreen on the Tree view.

  2. In the app authoring menu, select Insert (+).

  3. Select Text label.

  4. Drag the label to the top right of the screen next to the UserLabel.

  5. In the app authoring menu, select Tree view.

  6. Rename the label to UserDetailsLabel.

  7. Set the Text property of UserDetailsLabel in the formula bar to:

     Office365Users.MyProfile().Country
    
  8. Set the properties of the label in the formula bar as follows:

    1. X=930
    2. Y=20
    3. Size=18
    4. Color=Color.White
  9. Select Save in the top-right of the Power Apps Studio.

  10. Select the <- Back button from the top left of the command bar, and select Leave to exit the app.