在應用程式中啟動流程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,不包含清單。Note: 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. 新增 Text input 控制項並命名為 RecordTitleAdd a Text input control, and name it RecordTitle.
  4. 新增 Button 控制項,然後將它移動至 RecordTitle下。Add a Button control, and move it under RecordTitle.
  5. 選取 Button 控制項,然後選取 [動作] 索引標籤上的 [流程]。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 是否設定為您建立流程的環境。Note: 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.