使用 Microsoft Flow 中的“应用到每个操作”可定期处理一系列的项目Use the apply to each action in Microsoft Flow to process a list of items periodically

许多触发器可以基于某个事件(例如,当新的电子邮件到达收件箱中时)立即启动流。Many triggers can immediately start a flow based on an event such as when a new email arrives in your inbox. 这些触发器很好,但有时你想要运行某个流以便按照预定义计划查询数据源,根据数据源中项目的属性执行某些操作。These triggers are great, but sometimes you want to run a flow that queries a data source on a predefined schedule, taking certain actions based on the properties of the items in the data source. 为此,可以按照计划(如每日一次)启动流,并且使用循环操作(如“应用到每个”)处理一系列的项目。To do this, your flow can be started on a schedule (such as once per day) and use a loop action such as Apply to each to process a list of items. 例如,可以使用“应用到每个”来更新数据库中的记录或 Microsoft SharePoint 中的一系列项目。For example, you could use Apply to each to update records from a database or list of items from Microsoft SharePoint.

在本演练中,我们将创建每 15 分钟运行一次并执行以下任务的流:In this walk-through, we'll create a flow that runs every 15 minutes and does the following:

  1. 获取 Office 365 Outlook 收件箱中最后 10 封未读的邮件。Gets the last 10 unread messages in your Office 365 Outlook Inbox.
  2. 检查 10 封邮件中的每一封,以确认是否有某封邮件的主题中包含“立即开会”。Checks each of the 10 messages to confirm if any has meet now in the subject.
  3. 检查是否该电子邮件来自于你的老板或已在重要性标记为“高”的情况下发送。Checks if the email is from your boss or was sent with high importance.
  4. 发送推送通知,并将满足以下条件的任何电子邮件标记为已读:主题中包含“立即开会”,并且来自于你的老板或已在重要性标记为“高”的情况下发送。Sends a push notification and marks as read any email that has meet now in the subject and is either from your boss or was sent with high importance.

此图显示了我们将在本演练中创建的流的详细信息:This diagram shows the details of the flow we'll create in this walk-through:

正在生成的流的概览

先决条件Prerequisites

下面是在此演练中成功执行这些步骤的要求:Here are the requirements for successfully performing the steps in this walk-through:

  • 为使用 Microsoft Flow 而注册的帐户。An account that's registered to use Microsoft Flow.
  • Office 365 Outlook 帐户。An Office 365 Outlook account.
  • 适用于 AndroidiOSWindows Phone 的 Microsoft Flow 移动应用。The Microsoft Flow mobile app for Android, iOS, or Windows Phone.
  • 与 Office 365 Outlook 和推送通知服务的连接。Connections to Office 365 Outlook and the push notification service.

创建流Create a flow

  1. 登录到 Microsoft FlowSign into Microsoft Flow:

  2. 选择“我的流”选项卡,然后从空白创建一个流:Select the My flows tab, and then create a flow from a blank:

    从空白创建

  3. 在搜索框中输入“计划”以搜索所有与制定计划相关的服务和触发器。Enter "schedule" into the search box to search for all services and triggers that are related to scheduling.

  4. 选择“计划 - 重复周期”触发器,以指示你的流将按照随后你将提供的计划运行:Select the Schedule - Recurrence trigger to indicate that your flow will run on a schedule that you'll provide next:

    安排定期计划操作

  5. 将计划设置为每 15 分钟运行一次:Set the schedule to run every 15 minutes:

    计划运行

  6. 依次选择“+ 新步骤”、“添加操作”,然后将 outlook 键入到搜索框以搜索所有与 Microsoft Outlook 相关的操作。Select + New step, Add an action, and then type outlook into the search box to search for all actions related to Microsoft Outlook.

  7. 选择“Office 365 Outlook - 获取电子邮件”操作:Select the Office 365 Outlook - Get emails action:

    选择“获取电子邮件”操作

  8. 这将打开“获取电子邮件”卡。This will open the Get emails card. 将“获取电子邮件”卡配置为从收件箱文件夹中选择顶部的 10 封未读电子邮件。Configure the Get emails card to select the top 10 unread emails from the Inbox folder. 请勿包含附件,因为不会在流中使用它们:Don't include attachments because they won't be used in the flow:

    配置电子邮件卡

    备注

    到目前为止,你已创建可从收件箱获取一些电子邮件的简单流。So far, you've created a simple flow that gets some emails from your inbox. 这些电子邮件将以数组的形式返回;“应用到每个”操作需要一个数组,因此这正是所需的。These emails will be returned in an array; the Apply to each action requires an array, so this is exactly what's needed.

添加操作和条件Add actions and conditions

  1. 依次选择“+ 新步骤”、“更多”、“添加‘应用到每个’”操作:Select + New step, More, and then Add an apply to each action:

    选择“应用到每个”

  2. 将“正文”标记插入到“应用到每个”卡上的“从先前的步骤中选择一个输出”框中。Insert the Body token into the Select an output from previous steps box on the Apply to each card. 这将拉入要在“应用到每个”操作中使用的电子邮件正文:This pulls in the body of the emails to be used in the Apply to each action:

    添加正文标记

  3. 选择“添加条件”:Select Add a condition:

    添加条件

  4. 配置“条件”卡以在每封电子邮件的主题中搜索词“立即开会”:Configure the Condition card to search the subject of each email for the words "meet now":

    • 将“主题”标记插入到“对象名称”框中。Insert the Subject token into the Object Name box.

    • 在“关系”列表中选择“包含”。Select contains in the Relationship list.

    • 在“值”框输入“立即开会”。Enter meet now into the Value box.

      配置条件

  5. 选择“更多”,然后从“如果是,则不执行任何操作”分支选择“添加条件”。Select More, and then select Add a condition from the IF YES, DO NOTHING branch. 这将打开“条件 2”卡;配置该卡,如下所示:This opens the Condition 2 card; configure that card like this:

    • 将“重要性”标记插入到“对象名称”框中。Insert the Importance token into the Object Name box.

    • 在“关系”列表中选择“等于”。Select is equal to in the Relationship list.

    • 将“高”输入到“值”框中。Enter High into the Value box.

      添加条件

  6. 选择“如果是,则不执行任何操作”部分下的“添加操作”。Select Add an action under the IF YES, DO NOTHING section. 这将打开“选择操作”卡,其中你将定义在满足搜索条件(“立即开会”电子邮件已在重要性标记为“高”的情况下发送)时应发生的操作:This will open the Choose an action card, where you'll define what should happen if the search condition (the meet now email was sent with high importance) is true:

    添加操作

  7. 搜索通知,然后选择“通知 - 向我发送移动通知”操作:Search for notification, and then select the Notifications - Send me a mobile notification action:

    搜索和选择通知

  8. 在“向我发送移动通知”卡上,为将在电子邮件的主题包含“立即开会”的情况下发送的推送通知提供详细信息,然后选择“添加操作”:On the Send me a mobile notification card, provide the details for the push notification that will be sent if the subject of an email contains "meet now", and then select Add an action:

    配置通知

  9. 输入“已读”作为搜索词,然后选择“Office 365 Outlook - 标记为已读”操作。Enter read as the search term, and then select the Office 365 Outlook - Mark as read action. 这会在发送推送通知后将每封电子邮件标记为已读:This will mark each email as read after the push notification is sent:

    添加“标记为已读”操作

  10. 将“消息 ID”标记添加到“标记为已读”卡的“消息 ID”框。Add the Message Id token to the Message Id box of the Mark as read card. 可能需要选择“查看更多”来查找“消息 ID”标记。You may need to select See more to find the Message Id token. 这指示将被标记为已读的消息的 ID:This indicates the Id of the message that will be marked as read:

    添加消息 ID

  11. 返回到“条件 2”卡上的“如果否,则不执行任何操作”分支:Going back to the Condition 2 card, on the IF NO, DO NOTHING branch:

    • 选择“添加操作”,然后将“获取经理”键入到搜索框中。Select Add an action, and then type get manager into the search box.

    • 从搜索结果列表中选择“Office 365 用户 - 获取经理”操作。Select the Office 365 Users - Get manager action from the search results list.

    • 将你的 完整电子邮件地址输入到“获取经理”卡的“用户”框中。Enter your full email address into the User box of the Get Manager card.

      添加和配置“获取经理”操作

  12. 选择“更多”,然后从“如果否”分支选择“添加条件”。Select More, and then select Add a condition from the IF NO branch. 这将打开“条件 3”卡;将该卡配置为检查电子邮件发件人的电子邮件地址(“发件人”标记)是否与你老板的电子邮件地址(“电子邮件”标记)相同:This opens the Condition 3 card; configure the card to check if the email sender's email address (the From token) is the same as your boss' email address (the Email token):

    • 将“发件人”标记插入到“对象名称”框中。Insert the From token into the Object Name box.

    • 在“关系”列表中选择“包含”。Select contains in the Relationship list.

    • 将“电子邮件”标记输入到“值”框中。Enter Email token into the Value box.

      配置搜索条件

  13. 选择“条件 3”卡的“如果是,则不执行任何操作”部分下的“添加操作”。Select Add an action under the IF YES, DO NOTHING section of the Condition 3 card. 这将打开“如果是”卡,其中你将定义在满足搜索条件(电子邮件来自于你的老板)时应发生的操作:This will open the IF YES card, where you'll define what should happen if the search condition (the email was sent from your boss) is true:

    配置条件

  14. 搜索通知,然后选择“通知 - 向我发送移动通知”操作:Search for notification, and then select the Notifications - Send me a mobile notification action:

    搜索通知操作

  15. 在“向我发送移动通知 2”卡上,为将在电子邮件来自于你老板的情况下发送的推送通知提供详细信息,然后选择“添加操作”:On the Send me a mobile notification 2 card, provide the details for the push notification that will be sent if the email is from your boss, and then select Add an action:

    配置通知卡

  16. 添加“Office 365 Outlook - 标记为已读”操作。Add the Office 365 Outlook - Mark as read action. 这会在发送推送通知后将每封电子邮件标记为已读:This will mark each email as read after the push notification is sent:

    添加“标记为已读”操作

  17. 将“消息 ID”标记添加到“标记为已读 2”卡。Add the Message Id token to the Mark as read 2 card. 可能需要选择“查看更多”来查找“消息 ID”标记。You may need to select See more to find the Message Id token. 这指示将被标记为已读的消息的 ID:This indicates the Id of the message that will be marked as read:

    配置“标记为已读”操作

  18. 命名你的流,然后创建它:Name your flow, and then create it:

    为你的流提供名称并将其保存

如果你一直按照上述说明执行操作,你的流应类似于此图:If you followed along, your flow should look similar to this diagram:

已创建的流的概览

运行流Run the flow

  1. 向自己发送在主题中包括“立即开会”的高重要性电子邮件(或者让组织中的某人向你发送这样的电子邮件)。Send yourself a high-importance email that includes meet now in the subject (or have someone in your organization send you such an email).

  2. 确认该电子邮件在你的在收件箱中并处于未读状态。Confirm the email is in your inbox and it's unread.

  3. 登录到 Microsoft Flow,选择“我的流”,然后选择“立即运行”:Sign into Microsoft Flow, select My flows, and then select Run now:

    立即运行

  4. 选择“运行流”以确认你确实想要运行该流:Select Run flow to confirm you really want to run the flow:

    确认运行

  5. 几分钟后,你应看到成功运行的结果:After a few moments you should see the results of the successful run:

    运行结果

查看运行的结果View results of the run

现在已成功运行该流,应在移动设备上收到推送通知。Now that you've run the flow successfully, you should receive the push notification on your mobile device.

  1. 在移动设备上打开 Microsoft Flow 应用,然后选择“活动”选项卡。你将看到有关会议的推送通知:Open the Microsoft Flow app on your mobile device, and then select the Activity tab. You'll see the push notification about the meeting:

    选择活动选项卡

  2. 若要查看通知的完整内容,你可能需要选择通知。To see the full contents of the notification, you may have to select the notification. 你将看到完整的通知,类似于以下内容:You'll see the full notification, similar to this:

    通知详细信息

    备注

    如果没有收到推送通知,请确认移动设备具有有效的数据连接。If you don't receive the push notification, confirm that your mobile device has a working data connection.