使用 Microsoft Flow 和 Microsoft 通用数据服务生成审批循环Build an approval loop by using Microsoft Flow and the Microsoft Common Data Service

用户可以使用通用数据服务生成流,将信息存储在独立于流的数据库中。The Common Data Service can give you a way to build flows that have information stored in a database independent of a flow. 此方面的最佳示例是审批。The best example of this is with approvals. 如果将审批状态存储在实体中,则可在其基础上使用流。If you store the status of the approval in an entity, your flow can work on top of it.

在此示例中,需创建一个审批流程,该流程从用户将文件添加到 Dropbox 开始。In this example, you'll create an approval process that starts when a user adds a file to Dropbox. 添加文件以后,其相关信息就会显示在应用中,供审阅者批准或拒绝所做的更改。When the file is added, information about it appears in an app, where a reviewer can approve or reject the change. 在审阅者批准或拒绝所做的更改以后,将会发送通知邮件,并会从 Dropbox 中删除拒绝的文件。When the reviewer approves or rejects the change, notification mail is sent, and rejected files are deleted from Dropbox.

遵循此部分的步骤操作即可生成以下内容:By following the steps in this section, you'll build:

  • 自定义实体:其中包含添加到 Dropbox 中的每个文件的相关信息,以及文件的状态是“已批准”、“已拒绝”还是“挂起”。a custom entity that will contain information about each file added to Dropbox and whether the file's status is approved, rejected, or pending.
  • :当文件被添加到 Dropbox 时向自定义实体添加信息,当文件被批准或拒绝时发送邮件,以及删除被拒绝的文件。a flow that adds information to the custom entity when a file is added to Dropbox, sends mail when the file is approved or rejected, and deletes rejected files. 以下步骤演示如何从头开始生成此类流,不过也可通过模板创建类似的流。These steps demonstrate how to build such a flow from scratch, but you can create a similar flow from a template.
  • 应用:审阅者可以在其中批准或拒绝添加到 Dropbox 的文件。an app in which a reviewer can approve or reject files added to Dropbox. 需使用 PowerApps 根据自定义实体中的字段自动生成此应用。You'll use PowerApps to generate this app automatically based on the fields in the custom entity.

先决条件Prerequisites

生成实体Build the entity

  1. 登录到 powerapps.comSign in to powerapps.com.

  2. 如果默认情况下不显示左侧导航栏,请单击或点击左上角带三个水平线条的图标。If the left navigation bar doesn't appear by default, click or tap the icon with three horizontal lines in the upper-left corner.

    打开左侧导航栏

  3. 在左侧导航栏中,单击或点击“管理”,然后单击或点击“实体”。In the left navigation bar, click or tap Manage, and then click or tap Entities.

    管理实体

  4. 如果系统提示,请单击或点击“创建数据库”。If prompted, click or tap Create my database.

    创建数据库

  5. 在右上角附近单击或点击“新建实体”。Near the upper-right corner, click or tap New entity.

    创建实体

    如果浏览器窗口没有最大化,此按钮可能会出现在其他位置。If your browser window isn't maximized, this button might appear in a different place.

  6. 在“实体名称”下,指定一个不包含空格且尚未被数据库中其他实体使用的名称。Under Entity name, specify a name that doesn't contain spaces and that no other entity in your database has.

    若要严格按此示例操作,请指定 ReviewDropboxFilesTo follow this example exactly, specify ReviewDropboxFiles.

    指定实体名称

  7. 在“显示名称”下,指定一个易记名称。Under Display name, specify a friendly name.

    指定显示名称

  8. 单击或点击“下一步”。Click or tap Next.

    “下一步”按钮

将字段添加到实体Add fields to the entity

  1. 在右上角附近单击或点击“添加字段”。Near the upper-right corner, click or tap Add field.

    添加字段

  2. 在显示在字段列表底部的空行中,设置“审批者”字段的属性。In the blank row that appears at the bottom of the list of fields, set the properties of an Approver field. (设置这些属性时,按 Tab 键即可切换到下一列。)(As you set these properties, you can switch to the next column by pressing Tab.)

    • 在“显示名称”列中,键入“审批者”。In the Display Name column, type Approver.

    • 在“名称”列中,键入“ApproverEmail”。In the Name column, type ApproverEmail.

    • 在“类型”列中,单击或点击“电子邮件”选项。In the Type column, click or tap the Email option.

    • 在“必需”列中,选中相应的复选框。In the Required column, select the checkbox.

      “审批者”字段

  3. 在下一行中,设置“状态”字段的属性:In the next row, set the properties of a Status field:

    • 在“显示名称”列中,键入“状态”。In the Display Name column, type Status.

    • 在“名称”列中,键入“状态”。In the Name column, type Status.

    • 在“类型”列中,单击或点击“文本”选项。In the Type column, click or tap the Text option.

    • 在“属性”列中,保留默认值。In the Properties column, leave the default value.

    • 在“必需”列中,选中相应的复选框。In the Required column, select the checkbox.

      “状态”字段

  4. 在下一行中,设置“FileID”字段的属性:In the next row, set the properties of a FileID field:

    • 在“显示名称”列中,键入“文件标识符”。In the Display Name column, type File identifier.

    • 在“名称”列中,键入“FileID”。In the Name column, type FileID.

    • 在“类型”列中,单击或点击“文本”选项。In the Type column, click or tap the Text option.

    • 在“属性”列中,保留默认值。In the Properties column, leave the default value.

    • 在“唯一”列中,选中相应的复选框。In the Unique column, select the checkbox.

    • 在“必需”列中,选中相应的复选框。In the Required column, select the checkbox.

      “FileID”字段

  5. 在右侧靠近边缘的地方,单击或点击与“FileID”字段相对应的省略号 (...),然后单击或点击“设置为标题字段”。Near the right edge, click or tap the ellipsis (...) for the FileID field, and then click or tap Set as Title field.

    “设置标题”字段

  6. 在左下角附近单击或点击“创建”。Near the lower-left corner, click or tap Create.

    创建实体

  7. (可选)当实体列表重新显示时,如果浏览器窗口尚未最大化,可将其最大化,然后单击或点击“类型”列标题。(optional) When the list of entities reappears, maximize your browser window if it isn't already maximized, and then click or tap the Type column header. 此列表使用自定义实体(例如显示在顶部的刚创建的实体)排序。The list is sorted with the custom entities, such as the one you just created, appearing at the top.

登录并创建流Sign in and create a flow

  1. 打开 Microsoft Flow 门户Open the Microsoft Flow portal.

  2. 如果浏览器窗口尚未最大化,请将其最大化,然后单击或点击右上角附近的“登录”。Maximize your browser window if it isn't already maximized, and then click or tap Sign in near the upper-right corner.

    Microsoft Flow 的“登录”按钮

  3. 在右上角菜单中,选择用户在 powerapps.com 中创建数据库的环境。In the top right menu you select the environment that you created the database in powerapps.com.

    注意:如果未选择相同的环境,则将看不到用户的实体。Note: if you do not select the same environment then you will not see your entity.

  4. 在左下角附近单击或点击“我的流”。Near the upper-left corner, click or tap My flows.

    “我的流”按钮

  5. 在右上角附近单击或点击“创建新流”。Near the upper-right corner, click or tap Create new flow.

    “创建新流”按钮

添加文件时启动Start when a file is added

  1. 在包含“搜索更多触发器”的框中,键入或粘贴“Dropbox”,然后单击或点击“Dropbox - 创建文件时”。In the box that contains Search for more triggers, type or paste Dropbox, and then click or tap Dropbox - when a file is created.

    创建触发器

  2. 在“文件夹”下,单击或点击文件夹图标,然后浏览到将在其中添加文件的文件夹。Under Folder, click or tap the folder icon, and then browse to the folder where files will be added.

    选择文件夹

将数据添加到实体Add data to the entity

  1. 单击或点击“新建步骤”,然后单击或点击“添加操作”。Click or tap New step, and then click or tap Add an action.

    添加操作

  2. 在包含“搜索更多操作”的框中,键入或粘贴“通用数据服务”,然后单击或点击“通用数据服务 - 创建对象”。In the box that contains Search for more actions, type or paste Common Data Service, and then click or tap Common Data Service - Create object.

    在通用数据服务中创建对象

  3. 在“实体”下,键入或粘贴“审阅”,然后单击或点击“审阅 Dropbox 文件”。Under The entity, type or paste Review, and then click or tap Review Dropbox files.

    选择实体

  4. 在“标题”下,单击或点击相应的框,然后单击或点击参数标记列表中的“文件名”,将该标记添加到字段中。Under Title, click or tap in the box, and then click or tap File name in the list of parameter tokens to add that token to the field.

    添加文件名标记

  5. 在“审批者”下,键入或粘贴将审阅文件的人员的电子邮件地址。Under Approver, type or paste the email address of the person who will review the files.

    注意:若要使流的测试更容易些,请指定自己的地址。Note: To make testing the flow easier, specify your own address. 可以在以后当流能够实际使用时对其进行更改。You can change it later, when the flow is ready for actual use.

    添加审批者

  6. 在“状态”下,键入或粘贴“挂起”。Under Status, type or paste Pending.

    添加默认状态

  7. 在“文件标识符”下,单击或点击相应的框,然后单击或点击参数标记列表中的“文件标识符”,将该标记添加到字段中。Under File Identifier, click or tap in the box, and then click or tap File identifier in the list of parameter tokens to add that token to the field.

    添加文件标识符标记

检查是否已审阅过该文件Check whether the file has been reviewed

  1. 在“创建对象”操作下,依次单击或点击“新建步骤”、“更多”和“添加操作停止条件”。Under the Create object action, click or tap New step, click or tap More, and then click or tap Add a do until.

    添加操作停止条件

  2. 在“操作停止条件”操作的左上角,单击或点击包含“选择值”的框。In the upper-left corner of the Do until action, click or tap in the box that contains Choose a value.

    选择值

    注意:如果浏览器窗口没有最大化,请单击或点击包含“选择值”的上部框。Note: If your browser window isn't maximized, click or tap in the upper box that contains Choose a value.

  3. 在“从创建对象输出”下,单击或点击“状态”,将该参数标记添加到字段。Under Outputs from Create object, click or tap Status to add that parameter token to the field.

    添加“状态”标记

  4. 打开靠近“操作停止条件”操作中心的列表,然后单击或点击“不等于”。Open the list near the center of the Do until action, and then click or tap is not equal to.

    指定“不等于”

  5. 在“操作停止条件”操作的右上角,在包含“选择值”的框中键入或粘贴“挂起”。In the upper-right corner of the Do until action, type or paste Pending in the box that contains Choose a value.

    指定要监视的状态

    注意:如果浏览器窗口没有最大化,请单击或点击包含“选择值”的下部框。Note: If your browser window isn't maximized, click or tap in the lower box that contains Choose a value.

  6. 在“操作停止条件”操作的底部附近,单击或点击“添加操作”。Near the bottom of the Do until action, click or tap Add an action.

    在“操作停止条件”内部添加操作

  7. 在包含“搜索更多操作”的框中,键入“通用”,然后单击或点击“通用数据服务 - 获取对象”。In the box that contains Search for more actions, type Common, and then click or tap Common Data Service - Get object.

    获取对象

  8. 在“命名空间”下,单击或点击数据库。Under The namespace, click or tap your database.

  9. 在“实体”下,键入或粘贴“审阅”,然后单击或点击“审阅 Dropbox 文件”。Under The entity, type or paste Review, and then click or tap Review Dropbox files.

    选择实体

  10. 在“对象 ID”下,单击或点击相应的框,然后单击或点击“文件标识符”参数标记,将其添加到字段中。Under Object id, click or tap in the box, and then click or tap the File identifier parameter token to add it to the field.

    添加对象标识符

检查项目是否已批准Check whether the item has been approved

  1. 在“操作停止条件”操作下,单击或点击“新建步骤”,然后单击或点击“添加条件”。Under the Do-Until action, click or tap New step, and then click or tap Add a condition.

    添加条件

  2. 在条件的左上角,单击或点击包含“选择值”的框。In the upper-left corner of the condition, click or tap in the box that contains Choose a value.

    条件的左上角

    注意:如果浏览器窗口没有最大化,请单击或点击包含“选择值”的上部框。Note: If your browser window isn't maximized, click or tap in the upper box that contains Choose a value.

  3. 在“从获取对象输出”下,单击或点击“状态”参数标记,将其添加到字段。Under Outputs from Get object, click or tap the Status parameter token to add it to the field.

    将状态添加到条件

  4. 在条件的右上角,在包含“选择值”的框中键入或粘贴“已批准”。In the upper-right corner of the condition, type or paste Approved in the box that contains Choose a value.

    验证状态是否设置为“已批准”

    注意:如果浏览器窗口没有最大化,请在包含“选择值”的下部框中键入或粘贴“已批准”。Note: If your browser window isn't maximized, type or paste Approved in the lower box that contains Choose a value.

发送通知邮件Send notification mail

  1. 在“如果是,则不执行任何操作”下,单击或点击“添加操作”。Under If yes, do nothing, click or tap Add an action.

    如果是,则添加操作

  2. 在包含“搜索更多操作”的框中,键入或粘贴“发送邮件”,然后单击或点击“Office 365 Outlook - 发送电子邮件”。In the box that contains Search for more actions, type or paste send mail, and then click or tap Office 365 Outlook - Send an email.

    如果是,则发送邮件

  3. 在“收件人”下,键入或粘贴在接受某个项目时需通知的人员的地址。Under To, type or paste the address of the person whom you want to notify when an item is accepted.

    注意:若要使流的测试更容易些,请指定自己的地址。Note: To make testing the flow easier, specify your own address. 可以在流能够实际使用时对其进行更改。You can change it when the flow is ready for actual use.

    批准邮件收件人

  4. 在“主题”下,单击或点击相应的框,然后单击或点击“文件名”参数标记,将其添加到字段中。Under Subject, click or tap in the box, and then click or tap the File name parameter token to add it to the field.

    指定文件名作为电子邮件主题

  5. 在“正文”下,键入或粘贴“项目已批准。”Under Body, type or paste The item has been approved.

    批准邮件正文

  6. 在“如果否,则不执行任何操作”下,重复本过程的步骤 1-5,区别是将电子邮件消息的正文指定为“项目已拒绝。”Under If no, do nothing, repeat steps 1-5 in this procedure except specify the body of the email message as The item has been rejected.

    拒绝邮件正文

删除被拒绝的文件Delete rejected files

  1. 在拒绝邮件的字段下,单击或点击“添加操作”。Under the fields for the rejection mail, click or tap Add an action.

    添加删除操作

  2. 在包含“搜索更多操作”的框中,键入或粘贴“Dropbox”,然后单击或点击“Dropbox - 删除文件”。In the box that contains Search for more actions, type or paste Dropbox, and then click or tap Dropbox - Delete file.

    从 Dropbox 中删除文件

  3. 在“文件”下,单击或点击相应的框,然后单击或点击“文件标识符”标记参数,将其添加到字段中。Under File, click or tap in the box, and then click or tap the File identifier token parameter to add it to the field.

    标识要删除的文件

保存流Save the flow

  1. 在屏幕顶部,键入或粘贴要创建的流的名称,然后单击或点击“创建流”。At the top of the screen, type or paste a name for the flow that you're creating, and then click or tap Create Flow.

    保存流

  2. 单击或点击“关闭”,然后单击或点击“完成”。Click or tap Close and then click or tap Done.

  3. 在 Dropbox 中,向指定文件夹添加至少两个文件:一个用于测试批准情况,一个用于测试拒绝情况。In Dropbox, add at least two files to the folder that you specified: one to test approval and one to test rejection.

生成应用Build the app

  1. 登录到 powerapps.com,然后单击或点击左侧导航栏底部附近的“新建应用”。Sign in to powerapps.com, and then click or tap New app near the bottom of the left navigation bar.

    在浏览器中创建应用

  2. 在显示的对话框中,单击或点击相关选项,打开用于 Windows 的 PowerApps Studio 或用于 Web 的 PowerApps Studio。In the dialog box that appears, click or tap the option to open either PowerApps Studio for Windows or PowerApps Studio for the web.

  3. 如果已打开用于 Windows 的 PowerApps Studio,请在左侧导航栏中单击或点击“新建”。If you opened PowerApps Studio for Windows, click or tap New in the left navigation bar.

  4. 在“根据数据创建应用”下的“通用数据服务”磁贴中,单击或点击“手机布局”。Under Create an app from your data, click or tap Phone layout in the Common Data Service tile.

    创建应用

  5. 在“搜索”框中,键入或粘贴“审阅”。In the Search box, type or paste Review.

    搜索实体

  6. 在“选择实体”下,单击或点击“审阅 Dropbox 文件”。Under Choose an entity, click or tap Review Dropbox Files.

    选择实体

  7. 在右下角附近单击或点击“连接”。Near the lower-right corner, click or tap Connect.

    “连接”按钮

  8. 如果出现简介教程的起始屏幕,可学习该教程,熟悉一下 PowerApps(或者单击或点击“跳过”)。If the opening screen of intro tour appears, take the tour to get familiar with PowerApps (or click or tap Skip).

    简介教程

    用户始终可以在以后学习此教程,只需单击或点击左上方附近的问号图标,然后单击或点击“学习简介教程”即可。You can always take the tour later by clicking or tapping the question-mark icon near the upper-left corner and then clicking or tapping Take the intro tour.

  9. (可选)可以在屏幕底部附近拖动滑块来增大缩放比例,使应用看起来更清楚。(optional) Near the bottom of the screen, drag the slider to increase the zoom so the app is easier to see.

    缩放控件

自定义应用Customize the app

  1. 在右侧导航栏中,单击或点击包括标头和描述的布局。In the right navigation bar, click or tap the layout that includes a header and a description.

    “连接”按钮

  2. BrowseScreen 上,单击或点击搜索栏正下方,选择较大的文本框控件。On the BrowseScreen, click or tap just under the search bar to select the larger text-box control.

    选择标头

  3. 在右侧窗格中,单击或点击向下箭头打开下部的列表。In the right-hand pane, open the lower list by clicking or tapping its down arrow.

    打开下拉框

  4. 在下部列表中,单击或点击“标题”,显示已添加文件的文件名。In the lower list, click or tap Title so show the file name of the added files.

    设置标题数据

  5. 在右侧窗格中,打开上部列表,然后单击或点击“状态”,显示每个文件的状态。In the right-hand pane, open the upper list, and then click or tap Status to show the status of each file.

    设置正文数据

测试总体解决方案Test the overall solution

  1. 在 PowerApps 中,单击或点击左上方附近的播放按钮,打开“预览”模式。In PowerApps, open Preview mode by clicking or tapping the play button near the upper-left corner.

    打开“预览”模式

  2. 对于列表中的第一个文件,单击或点击相关箭头即可显示该文件的详细信息。For the first file in the list, click or tap the arrow to show details about that file.

    打开“详细信息”屏幕

  3. 在右上角单击或点击铅笔图标,更改该文件的详细信息。In the upper-right corner, click or tap the pencil icon to change details about the file.

    打开“编辑”屏幕

  4. 在“状态”框中,键入或粘贴“已批准”。In the Status box, type or paste Approved.

    审核文件

  5. 在右上角单击或点击复选标记图标,保存所做的更改并返回到“详细信息”屏幕。In the upper-right corner, click or tap the checkmark icon to save your changes and return to the details screen.

    保存所做的更改

    在数分钟内即可收到电子邮件,指出文件已批准。In a few minutes, you'll receive email stating that the file was approved.

  6. 在右上角单击或点击后退按钮,返回到“浏览”屏幕。In the upper-right corner, click or tap the back button to return to the browse screen.

    返回到“浏览”屏幕

  7. 对于列表中的另一个文件,单击或点击相关箭头即可显示该文件的详细信息。For the other file in the list, click or tap the arrow to show details about that file.

    打开“详细信息”屏幕

  8. 在右上角单击或点击铅笔图标,更改该文件的详细信息。In the upper-right corner, click or tap the pencil icon to change details about the file.

    打开“编辑”屏幕

  9. 在“状态”框中,键入或粘贴“已拒绝”(或者键入或粘贴除“已批准”以外的任何内容,例如“Aproved”或“Approoved”)。In the Status box, type or paste Rejected (or anything except Approved, including Aproved or Approoved).

    拒绝文件

  10. 在右上角单击或点击复选标记图标,保存所做的更改并返回到“详细信息”屏幕。In the upper-right corner, click or tap the checkmark icon to save your changes and return to the details screen.

    保存所做的更改

    在数分钟内即可收到电子邮件,指出文件被拒绝,将从 Dropbox 中删除。In a few minutes, you'll receive email stating that the file was rejected, and the file will be deleted from Dropbox.