启动应用中的流Start a flow in an app

可以使用 Microsoft Flow 来创建逻辑,以便在应用中发生某个事件时执行一个或多个任务。You can use Microsoft Flow to create logic that performs one or more tasks when an event occurs in an app. 例如,配置一个按钮,以便用户选择它时在 SharePoint 列表中创建一个项、发送电子邮件或会议请求、将文件添加到云,或执行所有上述操作。For example, configure a button so that, when a user selects it, an item is created in a SharePoint list, an email or meeting request is sent, a file is added to the cloud, or all of these. 可以在应用中配置任何用于启动流的控件,该控件在关闭 PowerApps 的情况下仍会继续运行。You can configure any control in the app to start the flow, which continues to run even if you close PowerApps.

先决条件Prerequisites

  • 注册 PowerApps,然后执行下列步骤之一:Sign up for PowerApps, and then follow either of these steps:

    • Windows 应用商店中,安装并打开适用于 Windows 的 PowerApps Studio,再提供注册时使用的同一凭据进行登录。In the Windows Store, install PowerApps Studio for Windows, open it, and then sign in by providing the same credentials that you used to sign up.
    • powerapps.com 中,单击或点击左下角的“新应用”,打开适用于 Web 的 PowerApps Studio。In powerapps.com, open PowerApps Studio for web by clicking or tapping New app in the lower-left corner.
  • 了解如何配置控件Learn how to configure a control.

创建流Create a flow

  1. 登录 powerapps.com,再选择左侧导航栏中的“流”。Sign in to powerapps.com, and then select Flows in the left navigation bar.

  2. 在“我的流”页上,选择“从空白创建”。On the My Flows page, select Create from blank.

    用于在不使用模板的情况下创建流的选项

    “PowerApps”被添加为默认触发器。PowerApps is added as the default trigger.

    PowerApps 被添加为启动流的触发器

  3. 选择“新建步骤”,然后选择“添加操作”。Select New step, and then select Add an action.

    用于添加操作的选项

  4. 在“搜索所有服务和操作”框中,指定流操作,如以下示例所示:In the box that says Search all services and actions, specify an action for your flow, as in this example:

    1. 在框中键入“SharePoint”,再选择“操作”下列表中的“SharePoint - 创建项”。Type SharePoint in the box, and then select SharePoint - Create item in the list under Actions.

      用于创建 SharePoint 项的选项

    2. 如果系统提示,请提供用于连接到 SharePoint 的凭据。If prompted, provide credentials to connect to SharePoint.

    3. 在“网站地址”框中,键入或粘贴包含列表的 SharePoint Online 网站的 URL。In the Site Address box, type or paste the URL of a SharePoint Online site that contains a list.

      备注

      请指定不含列表的网站 URL。Specify the URL for the site not including the list.

    4. 在“列表名称”框中,选择要使用的列表。In the List Name box, select the list that you want to use.

    5. 单击或点击“标题”框,再选择“添加动态内容”。Click or tap the Title box, and then select Add dynamic content.

      将“在 PowerApps 中询问”参数添加到“标题”字段

    6. 在参数列表中,选择“在 PowerApps 中询问”。In the list of parameters, select Ask in PowerApps.

      添加参数

  5. (可选)指定一个或多个其他操作,如将审批邮件发送到指定的地址,或创建其他数据源中的相关条目。(optional) Specify one or more additional actions, such as sending approval mail to an address that you specify or creating a related entry in another data source.

  6. 在屏幕顶部附近,键入或粘贴流的名称,然后选择“创建流”。Near the top of the screen, type or paste a name for your flow, and then select Create flow.

    命名并保存流

向应用添加流Add a flow to an app

  1. 在 PowerApps 中,选择“文件”菜单中的“新建”。In PowerApps, select New in the File menu.

  2. 在“空白应用”磁贴上,选择“手机布局”。On the Blank app tile, select Phone layout.

  3. 添加文本输入控件,将其命名为 RecordTitleAdd a Text input control, and name it RecordTitle.

  4. 添加按钮控件,将其移至 RecordTitle 下。Add a Button control, and move it under RecordTitle.

  5. 选择按钮控件后,在“操作”选项卡上选择“流”。With the Button control selected, select Flows on the Action tab.

    “操作”选项卡上的“流”选项

  6. 在显示的窗格中,选择在前面的过程中创建的流。In the pane that appears, select the flow that you created in the previous procedure.

    备注

    如果创建的流不可用,请确认是否已将 PowerApps 设置为在其中创建了流的环境。If the flow that you created isn't available, confirm whether PowerApps is set to the environment in which you created the flow.

    从自定义窗格添加流

  7. 在公式栏中,在已自动添加的公式末尾键入或粘贴 RecordTitle.Text)In the formula bar, type or paste RecordTitle.Text) at the end of the formula that's been automatically added.

    包含流的 OnSelect 属性

测试流Test the flow

  1. 按 F5(或选择右上角附近的箭头)打开“预览”。Open Preview by pressing F5 (or by selecting the arrow near the upper-right corner).

    包含流的 OnSelect 属性

  2. 在“RecordTitle”中键入或粘贴文本,再单击或点击“按钮”控件。Type or paste text in RecordTitle, and then click or tap the Button control.

    此时会在指定的列表中创建一个 SharePoint 项,其标题为指定的文本。A SharePoint item is created in the list you specified with the text you specified as the title. 如果列表在流运行时处于打开状态,可能需要刷新浏览器窗口,才能显示这些更改。If the list was open when the flow ran, you might need to refresh your browser window to show the changes.