从 PowerApps 连接到 Dynamics 365Connect to Dynamics 365 from PowerApps

通过 PowerApps,可使用很少的代码或无需代码,快速生成、自定义、共享和运行移动应用。PowerApps lets you quickly generate, customize, share, and run mobile apps with little or no code. 通过使用 Dynamics 365 连接器,只需几分钟,即可创建有用的移动应用,与组织实现共享。By using the Dynamics 365 connector, you can create useful mobile apps to share with your organization in just a few minutes.

按照本主题中的步骤操作,可创建相关应用,用户可在此应用中浏览、添加、删除和更新 Dynamics 365 中的联系人。By following the steps in this topic, you'll create an app in which users can browse, add, delete, and make updates to contacts in Dynamics 365. 用户可通过浏览器移动设备(如手机)运行该应用。Users can run the app in a browser or on a mobile device such as a phone.

先决条件Prerequisite

若要遵照本教程操作,需要一个包含 Dynamics 365 订阅的 Microsoft Office 365 帐户。To follow this tutorial, you need a Microsoft Office 365 account that includes a Dynamics 365 subscription.

创建连接Create a connection

  1. 登录 PowerAppsSign in to PowerApps.
  2. 在左侧导航窗格中,单击“连接”。In the left navigation pane, click Connections.

    “文件”菜单上的“连接”选项

  3. 在右上角附近,单击“新建连接”。Near the upper-right corner, click New connection.

    新建连接

  4. 在连接列表中,单击 Dynamics 365In the list of connections, click Dynamics 365.

    “文件”菜单上的“连接”选项

  5. 在对话框中,单击“创建”。In the dialog box, click Create.

    创建连接

  6. 在“登录你的帐户”对话框中,提供 Dynamics 365(联机)租户凭据。In the Sign in to your account dialog box, provide your credentials for the Dynamics 365 (online) tenant.

    将创建一个连接。A connection is created.

自动生成应用Generate an app automatically

  1. 登录 PowerApps,然后单击左下角附近的“新建应用”。Sign in to PowerApps, and then click New app near the lower-left corner.

    新建应用

  2. 在“开始使用数据”下,单击“Dynamics 365”磁贴上的“手机布局”。Under Start with your data, click Phone layout on the Dynamics 365 tile.

    PowerApps 选择 Dynamics 365 连接器

  3. 在“连接”下,选择所需的连接,然后选择将在应用中管理的 Dynamics 365 实例的相应数据集。Under Connections, select the connection that you want, and then choose a dataset, which corresponds to the instance of Dynamics 365 that you'll manage in the app.
  4. 在“选择表”下,单击“联系人”,然后单击“连接”。Under Choose a table, click Contacts, and then click Connect.
  5. 在左侧导航栏中,单击或点击右上角的图标,切换到缩略图视图。In the left navigation bar, click or tap an icon in the upper-right corner to switch to the thumbnail view.

    切换视图

PowerApps 会根据联系人记录生成三屏应用。PowerApps generates a three-screen app based on contact records.

  • BrowseScreen1BrowseScreen1. 用户打开应用时默认显示此屏幕。This screen appears by default when users open the app. 在左侧导航栏中,此屏幕的缩略图显示在其他两个屏幕上方。In the left navigation bar, a thumbnail for this screen appears above the other two screens.
  • DetailScreen1DetailScreen1. 用户单击 BrowseScreen1 中的某项时,将显示此屏幕。This screen appears when users click an item in BrowseScreen1. 在左侧导航栏中,DetailScreen1 的缩略图显示在其他两个屏幕之间。In the left navigation bar, a thumbnail for DetailScreen1 appears between the other two screens.
  • EditScreen1EditScreen1. 用户单击 DetailScreen1 中某项的编辑图标时,将显示此屏幕。This screen appears when users click the edit icon for an item in DetailScreen1. 在左侧导航栏中,EditScreen1 的缩略图显示在其他两个屏幕下方。In the left navigation bar, a thumbnail for EditScreen1 appears under the other two screens.

应用可以其初始状态运行,但可通过改进每个屏幕上的信息使其更有用。The app can run in its initial state, but we can make it more useful by refining the information on each screen.

自定义 BrowseScreen1Customize BrowseScreen1

在此过程中,将配置 BrowseScreen1 以显示每个联系人的姓氏和名字。In this procedure, you'll configure BrowseScreen1 to show the first and last names of each contact. 数据将按姓氏的字母顺序排序,并在两列式网格中包含图像。The data will be sorted alphabetically by last name and include images in a two-column grid.

  1. BrowseScreen1 中,单击除第一条记录之外的任意记录可选择库。In BrowseScreen1, select the gallery by clicking any record in it except the first one.

    选择布局

  2. 在右侧窗格中,单击或点击“数据”选项卡。In the right-hand pane, click or tap the Data tab.
  3. 在布局列表中,单击或点击在两列式网格中显示图片和文本的布局。In the list of layouts, click or tap the one that shows pictures and text in a two-column grid.

    可能需要向下滚动以显示此选项。You might need to scroll down to show this option.

    选择布局

  4. 复制此公式,在库仍处于选中状态的情况下,在编辑栏(fx 按钮的右侧)中粘贴该公式:Copy this formula and then, with the gallery still selected, paste the formula in the formula bar (to the right of the fx button):

    SortByColumns(Search(Filter(Contacts,statuscode=1), TextSearchBox1.Text, "lastname"), "lastname", If(SortDescending1, Descending, Ascending))

  5. 在右侧窗格中,将顶部下拉列表设置为 firstname,中间的下拉列表设置为 lastnameIn the right-hand pane, set the top drop-down list to firstname and the middle drop-down list to lastname.

    选择 Body1

  6. (可选)在“文件”菜单上,单击“另存为”,键入应用的名称,然后单击“保存”。(optional) On the File menu, click Save as, type a name for the app, and then click Save.

    默认情况下,将应用保存到云。By default, the app will be saved to the cloud. 单击“此计算机”可本地保存应用。Click This computer to save your app locally.

自定义 DetailsScreen1 和 EditScreen1Customize DetailsScreen1 and EditScreen1

  1. 在左侧导航栏中,单击中间的缩略图,选择 DetailsScreen1In the left navigation bar, click the middle thumbnail to select DetailsScreen1.
  2. DetailScreen1 上,单击标题栏下的任意位置,以在右侧窗格中显示自定义选项。On DetailScreen1, click anywhere below the title bar to show customization options in the right-hand pane.

    显示窗体自定义

  3. 在右侧窗格中,单击每个字段的眼睛图标可将其隐藏。In the right-hand pane, click the eye icon for each field to hide it.

    隐藏字段

  4. 单击标题栏下的任意位置,选择 Form1Click anywhere under the title bar to select Form1.

    选择 Form1

  5. 在右侧窗格中,单击这些字段的眼睛图标,使屏幕显示每个联系人的图像(如果表包含图像)和其他四个字段:In the right-hand pane, click the eye icon for each of these fields, so that the screen will show an image (if the table contains one) and four other fields for each contact:

    • entityimageentityimage
    • firstnamefirstname
    • lastnamelastname
    • mobilephonemobilephone
    • emailaddress1emailaddress1

      右侧窗格应类似于此图:The right-hand pane should resemble this graphic:

      选择 Form1

  6. 在左侧导航栏中,单击底部的缩略图,选择 EditScreen1Select EditScreen1 by clicking the bottom thumbnail in the left navigation bar.
  7. 重复此过程中的这些步骤,以自定义 DetailsScreen1 的相同方式自定义 EditScreen1Repeat the steps in this procedure to customize EditScreen1 the same way as DetailsScreen1.
  8. (可选)保存应用。(optional) Save the app.

后续步骤Next steps