次の方法で共有


方法: Power Automate クラウド フローを Power Pages サイトと統合する

この記事では、Power Pages を作成し、Power Automate クラウド フローを使用して MSN 天気アプリを呼び出し、現在の天気の詳細をページに表示する方法について説明します。

前提条件

これらの手順を完了するには、Power Automate と Power Pages 環境が必要です。 ライセンスがない場合は、Power Pages および Power Automate の試用版にサインアップすることができます。

ステップ 1: クラウド フローを作成する

Power Pages トリガーを使用してフローを作成し、MSN 天気予報 アクションを使用して気象データを取得します。

  1. Power Pages にサインインします。

  2. サイト + + 編集 を選択します

  3. ワークスペースの設定 に移動し、アプリの統合で クラウド フロー を選択します。

  4. 選択 + 新しいフローを作成する

  5. Power Pagesを検索します。

    • Power Pages がフローを呼び出すとき トリガーを選択します。

    Power Automate で、Power Pages オプション を選択します。

  6. + 入力の追加を選択します。

  7. テキスト を選択します。

  8. 場所 として名前を追加します。

  9. + 新しいステップ を選択します。

  10. MSN 天気 を検索します。

  11. 現在の天気を取得する アクションを選択します。

  12. カーソルを 場所 入力テキストに合わせます。動的コンテンツから Power Pages がフローを呼び出すとき の下にある 場所 パラメーターを選択します。

    クラウド フローを構築します。

    注意

    ヤード ポンド法のままでも、メートル法に変更することもできます。

  13. + 新しいステップ を選択します。

  14. Power Pagesを検索します。

  15. Power Pages に値を返す アクションを選択します。

  16. + 追加および出力 を選択します。

  17. Textを選択します。

  18. タイトルとして 気圧 と入力します。

  19. 現在の天気を取得する で、動的コンテンツ 気圧 を選択します。

  20. 繰り返して、テキスト タイプを使用して次の出力ステップを作成します:

    1. 湿度
    2. 温度
    3. UV 指数
    4. 風速
    5. 場所
    6. 視認距離
    7. 経度
    8. 緯度
    9. 温度単位
    10. 気圧単位
    11. 速度単位
    12. 距離の単位
    13. 条件
  21. 保存を選択します

  22. フローに 現在の天気を取得する と名前を付けます。

ステップ 2: フローをステップに追加する

フローを保存した後、サイトに追加し、適切な Web ロールを割り当てる必要があります。

  1. Power Pages にサインインします。

  2. スターター レイアウト のいずれかを使用してサイトを作成します。

  3. そのサイトを選択し、編集 を選択します。

  4. 設定 ワークスペースに移動します。

  5. アプリの統合クラウド フロー を選択します。

  6. クラウド フローの追加 + を選択します。

  7. 現在の天気を取得するフロー を検索します。

  8. ロールで + ロールの追加 を選択します。

  9. 匿名ユーザー ロールを選択します。

  10. 追加を選択します。

  11. URL をコピーします。

    Web サイトにクラウド フローを追加します。

    注意

    これは、関連するクラウド フローに接続するために使用される固有の URL です。 後でこの URL を使用して、現在の天気フローを呼び出します。

ステップ 3: MSN 天気データを表示するページを作成する

フローを作成して Power Pages サイトに接続すると、JavaScript を使用してコントロール イベントから呼び出すことができます。

  1. ページ ワークスペースを選択します。

  2. + ページ を選択します。

  3. ページに "今日の天気予報" という名前を付けます。

  4. コードの編集 を選択して、Visual Studio Code を開きます。

  5. このコードを貼り付けます:

        <style>
            div.weatherdetail {
                border: 1px solid #F3F2F1;
                border-radius: 12px;
                box-shadow: 0px 1.2px 3.6px rgba(0, 0, 0, 0.1), 0px 6.4px 14.4px rgba(0, 0, 0, 0.13);
                padding: 24px;
            }
            .weather label {
                font-family: 'Nunito';
                font-style: normal;
                font-weight: 600;
                font-size: 18px;
                color: #323130;
            }
            .weather button {
                font-family: 'Segoe UI';
                padding: 8px 16px;
                font-size: 16px;
                background-color: #6219D9;
                color: white;
                border: none;
                border-radius: 4px;
                cursor: pointer;
                outline: none;
            } 
            div.weather {
                display: flex;
                flex-direction: column;
                align-items: flex-start;
                padding: 100px;
                gap: 36px;
                width: 840px;
            }
            span.temperature {
                font-family: Segoe UI;
                font-size: 96px;
                font-style: normal;
                font-weight: 600;
                color: #6219d9;
            }
            span.weatherinfov1 {
                font-family: Segoe UI;
                font-size: 28px;
                font-style: normal;
                font-weight: 400;
                color: #201f1e;
            }
            span.weatherinfov2 {
                font-family: Segoe UI;
                font-size: 24px;
                font-style: normal;
                font-weight: 600;
                color: #a19f9d;
            }
        </style>
    
        <div class="row sectionBlockLayout text-left" style="display: flex; flex-wrap: wrap; margin: 0px; min-height: auto; padding: 8px;">
            <div class="container" style="display: flex; flex-wrap: wrap;">
                <div class="col-md-12 columnBlockLayout weather" style="flex-grow: 1; display: flex; flex-direction: column; min-width: 310px; word-break: break-word; padding: 0 180px; margin: 60px 0px;">
                    <h1>What's the weather?</h1>
                    <form id="cityForm">
                        <label for="locationInput">Enter a location to find out</label>
                        <br>
                        <input type="text" style="width: 840px; border: 1px solid #D2D0CE;" id="locationInput" required />
                        <p>
                        <p>
                            <button type="submit">Submit</button>
                        </p>
                    </form>
                    <div id="weatherdetail" class="weatherdetail" style="display: none;width: 840px">
                        <div>
                            <div>
                                <span class="temperature" id="temperature"> </span>
                                <span class="weatherinfov1" id="temperature_units"></span>
                            </div>
                            <div>
                                <span class="weatherinfov1" style="font-size: 36px;" id="location"> </span>
                                <br>
                                <span class="weatherinfov1" style="font-size: 24px;" id="cordinates"></span>
                                <p>
                            </div>
                        </div>
                        <div style="display: flex;">
                            <div style="flex: 1;">
                                <span class="weatherinfov2">Wind: </span>
                                <span class="weatherinfov1" id="windspeed"></span>
                                <span class="weatherinfov1" id="speed_units"> </span>
                            </div>
                            <div style="flex: 1;">
                                <span class="weatherinfov2">Visibility: </span>
                                <span class="weatherinfov1" id="visibility"></span>
                                <span class="weatherinfov1" id="distance_units"></span>
                            </div>
                        </div>
                        <div style="display: flex;">
                            <div style="flex: 1;">
                                <span class="weatherinfov2">UV Index: </span>
                                <span class="weatherinfov1" id="uv"></span>
                            </div>
                            <div style="flex: 1;">
                                <span class="weatherinfov2">Conditions: </span>
                                <span class="weatherinfov1" id="condition"></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    
        <script>
            document.getElementById("cityForm").addEventListener("submit", function (event) {
                event.preventDefault(); // Prevent form submission
                var weatherDiv = document.getElementById("weatherdetail");
                weatherDiv.style.display = "none";
    
                var location = document.getElementById("locationInput").value;
    
                var _url = "<Cloud flow URL>";
    
              var data = {};
              data["Location"] = location;
    
                var payload = {};
                payload.eventData = JSON.stringify(data);
                shell
                    .ajaxSafePost({
                        type: "POST",
                        url: _url,
                        data: payload
                    })
                    .done(function (response) {
                        const result = JSON.parse(response);
                        document.getElementById("temperature").innerHTML = result["temperature"];
                        document.getElementById("windspeed").innerHTML = result["wind_speed"];
                        document.getElementById("visibility").innerHTML = result["visibility_distance"];
                        document.getElementById("uv").innerHTML = result["uv_index"];
                        document.getElementById("location").innerHTML = result["location"];
                        document.getElementById("condition").innerHTML = result["conditions"];
                        document.getElementById("temperature_units").innerHTML = result["temperature_units"];
                        document.getElementById("speed_units").innerHTML = result["speed_units"];
                        document.getElementById("distance_units").innerHTML = result["distance_units"];
                        document.getElementById("cordinates").innerHTML = parseFloat(result["latitude"]).toFixed(2) + ', ' + parseFloat(result["longitude"]).toFixed(2);
                        weatherDiv.style.display = "block";
                    })
                    .fail(function () {
                        alert("failed");
                    });
            });
        </script>
    
  6. 前の手順でコピーした URL に置き換えます。

  7. CTRL + S を選択してコードを保存します。

  8. デザイン スタジオで 同期 を選択します。

ステップ 4: フロー統合をテストする

フロー統合機能をテストするには:

  1. プレビュー を選択してサイトを開きます。

  2. 場所 テキスト ボックスに郵便番号または市区町村を入力します。

  3. 送信 ボタンを選択します。

    今日の天気予報を表示するフロー統合のレンダリング。