使用 Common Data Service 資料庫產生應用程式Generate an app by using a Common Data Service database

[!VIDEO nb:cid:UUID:6d7aa0a1-cd31-47c6-9a32-93b4e5476ece]

您可以自動產生應用程式來管理儲存在 Common Data Service 中的資料。You can automatically generate an app to manage data that is stored in Common Data Service. 您可以管理其中一個標準實體 (模型內建的實體) 的資料,或管理自訂實體 (您或組織中的其他人建立的實體) 的資料。You can manage data in one of the many standard entities that are built into the model, or in a custom entity that you or someone else in your organization creates.

如果您不熟悉 Common Data Service,請參閱了解實體If you're unfamiliar with Common Data Service, see Understand entities.

本主題將說明如何根據您所指定的單一實體自動產生應用程式。This topic describes how to automatically generate an app that is based on a single entity that you specify. 如需如何建置以一個以上實體為基礎的應用程式相關資訊,請參閱從頭開始建置應用程式For information about how to build an app that is based on more than one entity, see Build an app from scratch.

根據預設,Microsoft PowerApps 所產生的每個應用程式都有三個畫面:By default, every app that Microsoft PowerApps generates has three screens:

  • 瀏覽畫面會顯示一小組一或多個欄位、一個搜尋列,以及一個排序按鈕,讓使用者可輕鬆地找到特定的記錄。The browse screen shows a subset of one or more fields, a search bar, and a sort button that lets users easily find a specific record.
  • 詳細資料畫面會顯示特定記錄的更多或所有欄位。The details screen shows more or all fields for a specific record.
  • 編輯畫面會提供 UI 元素,讓使用者可用來建立或更新記錄並儲存其變更。The edit screen provides UI elements that let users create or update a record and save their changes.

注意︰當您從 Common Data Service 產生應用程式時,不需要從 PowerApps 建立連線,就如同您使用 SharePoint、Dynamics 365 和 Salesforce 等資料來源一樣。Note: When you generate an app from Common Data Service, you don't have to create a connection from PowerApps, as you do for data sources such as SharePoint, Dynamics 365, and Salesforce. 您只需指定您想要在應用程式中顯示、管理,或者顯示並管理的實體。You must specify only the entity that you want to show, manage, or show and manage in the app.

產生應用程式Generate an app

  1. 建立 Common Data Service 資料庫。Create a Common Data Service database. 如需詳細資訊,請參閱建立 Common Data Service 資料庫For more information, see Create a Common Data Service database.
  2. 在適用於 Windows 的 PowerApps Studio 中,按一下或點選 [檔案] 功能表 (靠近左側) 中的 [新增]。In PowerApps Studio for Windows, click or tap New on the File menu (near the left edge).
  3. 在 [從您的資料開始] 下方的 [Common Data Service] 圖格上,按一下或點選 [手機配置]。Under Start with your data, on the Common Data Service tile, click or tap Phone layout.
  4. 在 [選擇實體] 下,按一下或點選 [連絡人] 實體。Under Choose an entity, click or tap the Contact entity.
  5. 按一下或點選 [連接] 以自動產生應用程式。Click or tap Connect to automatically generate an app.

    此時,系統可能會提示您觀看簡介導覽。At this point, you may be prompted to take an introductory tour. 您日後也可以按一下或點選右上角附近的問號,然後按一下或點選 [簡介導覽],即可觀看導覽。You can also take the tour later by clicking or tapping the question mark near the upper-right corner, and then clicking or tapping Take the intro tour.

  6. 在左側的導覽列中按一下或點選右上角的圖示,切換至縮圖檢視。In the left navigation bar, click or tap an icon in the upper-right corner to switch to the thumbnail view.

    切換檢視

自訂瀏覽畫面Customize the browse screen

  1. 在右窗格中,按一下或點選只顯示標題的版面配置。In the right pane, click or tap the layout that shows just a heading.

    選取版面配置

  2. 在搜尋方塊中,按一下或點選標籤控制項以選取它。Under the search box, click or tap the Label control to select it.

    選取標籤

  3. 在右窗格中,從下拉式清單中選取 [名字的姓氏]。In the right pane, select Surname of Given name in the dropdown list

    您選取的標籤控制項會顯示該欄位的資料。The Label control that you selected shows data from that field.

  4. 在瀏覽畫面中,按一下或點選第一個名稱以外的任何名稱,以選取資源庫。In the browse screen, select the gallery by clicking or tapping any name except the top name.

    選取方塊會圍繞在資源庫四周。A selection box surrounds the gallery.

    選取資源庫

  5. 選取下列公式,然後按下 Ctrl+C,藉以複製公式。Copy the following formula by selecting it and then pressing Ctrl+C.

    SortByColumns(Search(Contact, TextSearchBox1.Text, "Name_Surname"), "Name_Surname", If(SortDescending1, Descending, Ascending))SortByColumns(Search(Contact, TextSearchBox1.Text, "Name_Surname"), "Name_Surname", If(SortDescending1, Descending, Ascending))

  6. 確定靠近左上角的屬性清單顯示的是 ItemsNear the upper-left corner, make sure that the property list shows Items.
  7. 在公式列中,選取預設公式。In the formula bar, select the default formula.

    Items 屬性的預設值

  8. 按下 Delete 鍵來刪除預設公式,然後貼上您所複製的公式。Press Delete to delete the default formula, and then paste the formula that you copied. 資源庫中的名稱會依字母順序排序。The names in the gallery are sorted alphabetically.

測試瀏覽畫面Test the browse screen

  1. 按下 F5 (或者按一下或點選靠近右上角的播放按鈕) 來開啟 [預覽] 模式。Open Preview mode by pressing F5, or by clicking or tapping the Play button near the upper-right corner.
  2. 使用觸控式螢幕或滑鼠滾輪,或利用滑鼠指向資源庫讓捲軸出現,以捲動所有記錄。Scroll through all the records by using a touchscreen or a mouse wheel, or by pointing to the gallery with a mouse so that the scroll bar appears.
  3. 按一下或點選靠近右上角的排序按鈕一或多次,以變更名稱排列的順序。Near the upper-right corner, click or tap the sort button one or more times to change order that the names are listed in.

    變更排序次序

  4. 在搜尋方塊中輸入字母,只顯示包含該字母的名稱。In the search box, type a letter to show only names that contain that letter.
  5. 從搜尋方塊中移除所有文字,然後按一下或點選清單中第一個名稱右邊的箭號。Remove all text from the search box, and then click or tap the arrow to the right of the first name in the list.

    詳細資料畫面隨即開啟,並顯示您所選取的連絡人詳細資訊。The details screen opens and shows more information about the contact you selected.

  6. 按下 Esc (或者按一下或點選標題列下方靠近右上角的關閉按鈕) 來返回設計工作區。Return to the design workspace by pressing Esc, or by clicking or tapping the Close button near the upper-right corner, under the title bar.

自訂其他畫面Customize the other screens

  1. 如果 [DetailScreen] 未顯示,請按一下或點選左側導覽列中間的縮圖。If DetailScreen isn't showing, click or tap the middle thumbnail in the left navigation bar.
  2. 在 [DetailScreen] 頂端附近,按一下或點選 [全名],以顯示在該畫面上自訂表單的選項。Near the top of DetailScreen, click or tap Full name to show options for customizing the form on that screen.
  3. 在右窗格中,按一下或點選 [Name_MiddleName] 的眼睛按鈕來隱藏該欄位。In the right pane, click or tap the eye button for Name_MiddleName to hide that field.
  4. 在右窗格中,按一下或點選 [Name_Surname] 的眼睛按鈕來顯示該欄位。In the right pane, click or tap the eye button for Name_Surname to show that field.
  5. 在右窗格中,向上拖曳 [Name_Surname],然後將它置於 [Name_GivenName] 的正下方。In the right pane, drag Name_Surname up, and drop it just under Name_GivenName.

    [DetailScreen] 會反映您的變更。The DetailScreen reflects your changes.

  6. 在左側導覽列中,按一下或點選底端的縮圖以顯示 [EditScreen],然後在此程序中重複執行先前的步驟,讓 [EditScreen] 符合 [DetailScreen]。In the left navigation bar, click or tap the bottom thumbnail to show EditScreen, and then repeat the previous steps in this procedure so that EditScreen matches DetailScreen.

測試應用程式Test the app

  1. 在左側導覽列中,按一下或點選頂端的縮圖影像以開啟瀏覽畫面。In the left navigation bar, click or tap the top thumbnail image to open the browse screen.
  2. 按下 F5 (或者按一下或點選靠近右上角的播放按鈕) 來開啟 [預覽] 模式。Open Preview mode by pressing F5, or by clicking or tapping the Play button near the upper-right corner.
  3. 在瀏覽畫面的右上角,按一下或點選加號按鈕 (+) 以建立記錄。In the upper-right corner of the browse screen, click or tap the plus sign button (+) to create a record.
  4. 在 [名字] 和 [姓氏] 欄位中新增文字,然後按一下或點選核取記號按鈕以儲存新的記錄,並返回瀏覽畫面。Add text in the Given name and Surname fields, and then click or tap the check mark button to save your new record and return to the browse screen.
  5. 找到您剛建立的記錄,然後按一下或點選記錄右側的箭號,即可在詳細資料畫面中顯示該記錄。Find the record that you just created, and then click or tap the arrow to the right of it to show the record on the details screen.
  6. 按一下或點選右上角的鉛筆按鈕,即可在編輯畫面中顯示該記錄。In upper-right corner, click or tap the pencil button to show the record on the edit screen.
  7. 變更 [名字] 欄位中的資料,然後按一下或點選核取記號按鈕以儲存變更。Change the data in the Given name field, and then click or tap the check mark button to save your changes.
  8. 按一下或點選靠近右上角的垃圾桶按鈕,即可刪除您所建立和更新的記錄。Near the upper-right corner, click or tap the trash-can button to delete the record that you created and updated.

後續步驟Next steps

使用 Common Data Service 資料庫從頭開始建立應用程式Create an app from scratch using a Common Data Service database