---
schema_version: "1"
id: a0af4fcebe6a72df039d067130587e73a45f99c351b052833041831eaee4985d
title: フローロジックへの条件の追加
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/anypoint-code-builder/tut-slack-add-condition-to-your-flow.md
canonical_url: https://docs.mulesoft.com/jp/anypoint-code-builder/tut-slack-add-condition-to-your-flow
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 7fd4eae8cc6bbb6d64ff78b6a0622efb3fb014138ec026c65468442acf238a98
description: MuleSoft Documentation Site
latest: true
---
# フローロジックへの条件の追加

**進行中のベータリリース**​: **クラウド IDE は進行中のベータリリースです**​。ベータ状態での Anypoint Code Builder の使用には、IDE で入手できる、該当するベータサービス契約条件が適用されます。

チュートリアルのこのセクションでは、Salesforce ケースがエスカレーションされた場合は地域リーダーにメールを送信し、それ以外の場合は Mule アプリケーションから Slack にメッセージを送信するための条件をフローに追加する方法について説明します。

## [](#始める前に)始める前に

次の手順を実行します。

1. [Slack およびメール通知への Salesforce データの統合](https://docs.mulesoft.com/jp/anypoint-code-builder/tut-slack-create-escalation-api)。
2. [Slack と Salesforce の設定ファイルの作成](https://docs.mulesoft.com/jp/anypoint-code-builder/tut-slack-create-config-files-sfdc)と Salesforce インテグレーションの設定。
3. [変数へのペイロード情報の抽出](https://docs.mulesoft.com/jp/anypoint-code-builder/tut-slack-extract-payload-information)。

## [](#ケースがエスカレーションされた場合の動作を定義する)ケースがエスカレーションされた場合の動作を定義する

Choice ルーターを使用して、特定の条件に基づいて動作を定義します。この場合、ケースがエスカレーションされた場合にメールを送信するように選択します。

1. Anypoint Code Builder で、​`new-case-salesforce.xml`​ ファイルを開きます。
2. Logger コンポーネントの ​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-plus.png)​ (​**\[Add component (コンポーネントを追加)\]**​) アイコンをクリックします。
    
    ![\[Add component (コンポーネントを追加)\] ボタンのアイコンが強調表示されているフロー図](_images/add-choice-router-slack-escalation-canvas.png)
3. `「choice」`​と入力して ​**\[Flow Control (フローコントロール)\]**​ の下の ​**\[Choice\]**​ を選択します。
4. `<when/>`​ および ​`<otherwise/>`​ 要素を追加します。
    
    ![テキスト「mule:when」が強調表示されている「when」の検索結果](/mulesoft/current/ja-jp/anypoint-code-builder/_images/sync-api-choice-when.png)
    
    ```XML
    <choice doc:name="Choice">
       <when doc:name="When" >
    
       </when>
       <otherwise doc:name="Otherwise" >
    
       </otherwise>
    
    </choice>
    ```
    
    Mule フローを読みやすくするために、​`<choice/>`​、​`<when/>`​、​`<otherwise/>`​ 要素の名前を更新します。
    
    ```XML
    <choice doc:name="Is Case Escalated?">
      <when doc:name="Escalated" >
    
      </when>
      <otherwise doc:name="Not Escalated" >
    
      </otherwise>
    </choice>
    ```
5. 変数 ​`casestatus`​ が ​`[Escalated (エスカレーション済み)]`​ の場合に実行されるように ​`when`​ 分岐を定義します。
    
    ```XML
    <choice doc:name="Is Case Escalated?">
      <when doc:name="Escalated" expression='#[vars.casestatus == "Escalated"]'>
    
      </when>
      <otherwise doc:name="Not Escalated" >
    
      </otherwise>
    </choice>
    ```

## [](#email-connector-を追加する)Email Connector を追加する

`<when/>`​ 要素を設定するには、まずメール用 Anypoint Connector (Email Connector) の操作を設定する必要があります。

1. Anypoint Code Builder で、​`new-case-salesforce.xml`​ ファイルを開き、​`<salesforce:sfdc-config/>`​ 要素の下に新しい行を追加します。
2. `「smtp」`​と入力して ​**email:smtp-config**​ を選択します。
    
    ```XML
    <email:smtp-config name="Email_SMTP">
      <email:smtps-connection host="${email.host}" user="${email.username}" password="${email.password}">
       <tls:context>
         <tls:trust-store insecure="true" />
       </tls:context>
      </email:smtps-connection>
    </email:smtp-config>
    ```
3. **\[Escalated (エスカレーション済み)\]**​ セクションの後の ​![](/mulesoft/current/ja-jp/anypoint-code-builder/_images/icon-plus.png)​ (​**\[Add component (コンポーネントを追加)\]**​) アイコンをクリックします。
    
    ![\[Escalated (エスカレーション済み)\]、\[Add component (コンポーネントを追加)\] ボタンのアイコンが強調表示されている Choice フロー](_images/add-email-operation-slack-integration-canvas.png)
4. `「send」`​と入力して ​**\[Email (メール)\]**​ セクションから ​**\[Send\]**​ を選択します。
    
    ![\[Send\] が強調表示されている検索結果セクションのコンポーネントのリスト](_images/send-email-slack-integration-canvas.png)
5. 次のコードサンプルを使用して、​`send`​ を設定します。
    
    ```XML
    <email:send config-ref="Email_SMTP" doc:name="Send Escalation Email" subject='#["Case " ++ vars.casenumber ++ " was escalated"]'>
      <email:to-addresses>
        <email:to-address value="${email.username}" />
      </email:to-addresses>
      <email:body contentType="text/html" >
        <email:content ><![CDATA[#["Please handle this case. " ++ payload]]]></email:content>
    </email:body>
    </email:send>
    ```
6. アプリケーションをテストできるようにするには、一時的に ​`<otherwise/>`​ 要素内に ​`<logger/>`​ 要素を追加します。
    
    ```XML
    <logger doc:name="Temporary Logger" message='#["Please look into this new Case: " ++ payload]'/>
    ```
7. Choice ルーターのすべての設定を調べます。
    
    ```XML
    <choice doc:name="Is Case Escalated?">
      <when doc:name="Escalated" expression='#[vars.casestatus == "Escalated"]'>
          <email:send config-ref="Email_SMTP" doc:name="Send Escalation Email" subject='#["Case " ++ vars.casenumber ++ " was escalated"]'>
                 <email:to-addresses>
                   <email:to-address value="${email.username}" />
                </email:to-addresses>
                <email:body contentType="text/html" >
                       <email:content ><![CDATA[#["Please handle this case. " ++ payload]]]></email:content>
                     </email:body>
               </email:send>
      </when>
      <otherwise doc:name="Not Escalated" >
        <logger doc:name="Temporary Logger" message='#["Please look into this new Case: " ++ payload]'/>
      </otherwise>
    </choice>
    ```

## [](#mule-アプリケーションをテストする)Mule アプリケーションをテストする

1. テストを効率化するには、Logger コンポーネントのブレークポイントを削除します。
2. **\[Run (実行)\]**​ > ​**\[Start Debugging (F5) (デバッグを開始 (F5))\]**​ を選択します。
3. アプリケーションが正常にデプロイされたら、Salesforce アカウントにログインします。
4. **アプリケーションランチャー**​から、​**\[サービス\]**​ を選択します。
    
    ![\[ホーム\] および \[サービス\] オプションが強調表示されている \[設定\] メニュー](_images/salesforce-select-service.png)
5. **\[ケース\]**​ > ​**\[新規ケース\]**​ を選択します。
    
    ![\[ケース\] セクションで \[新規ケース\] ボタンが強調表示されている \[サービス\] ナビゲーションバー](_images/salesfroce-create-new-case.png)
6. 新規ケースの ​**\[状況\]**​ が ​**\[エスカレーション済み\]**​ であることを確認します。
7. 数秒後、設定されたメールアカウントで、ケースで設定された情報が含まれるメールを受信していることを確認します。
    
    ```none
    Please handle this case. Case Number: 00001030, Origin: Phone, Case Type: , Priority: Medium, Status: Escalated
    ```
8. [「Slack インテグレーションの設定」](https://docs.mulesoft.com/jp/anypoint-code-builder/tut-slack-configure-integration)​に進み、エスカレーションされなかったケースの Slack メッセージの設定方法を確認します。