2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Power Apps でアプリの利用者ごとに Teams 通知先を設定する

Last updated at Posted at 2022-12-29

はじめに

今回は、以下のよな日報、勤務状況を同僚にシェアするアプリを例に、Power Apps でアプリの利用者ごとに通知先の Teams チャネルを設定する方法を紹介します。

image.png

これにより、通知先の Teams チャネルが異なるために、チームごとにアプリを分けて運用する必要がなくなり、広い範囲に展開がしやすいアプリとなります。

リモートワーク、ハイブリッドワークが増えたことで、今までと違う方法で同僚と日報や勤務状況等をシェアするニーズが高まったという認識です。個人的に Power Apps、Power Automate、Teams を組み合わせることで、このような情報のシェアが効率的にできると思います。
私が所属するチームでも、これらを組み合わせて働き方などを日々共有しております。

実装方法

今回は、以下のような設定画面を例に実装方法を紹介します。

image.png

Power Apps で Teams 通知先を設定する

こちらは非常にシンプルです。
まず、Teams コネクターを追加します。

image.png

コンボボックスを配置し、[Items] プロパティを以下のように設定します。

image.png

MicrosoftTeams.GetAllTeams().value

また、[DisplayFields][SearcFields] を displayName にしておきます。

image.png

次に、チャネル名についてもコンボボックスを配置し、[Items] プロパティを以下のように設定します。

image.png

MicrosoftTeams.GetChannelsForGroup(cmbTeamName.Selected.id).value

こちらも、[DisplayFields][SearcFields] を displayName にしておきます。

image.png

ボタンの [OnSelect] プロパティの処理は以下のようなイメージです。
※設定変更をする際の処理も書いています。

image.png

If(
    CountRows(colMySetting) = 0,
    Patch(
        通知先設定,
        Defaults(通知先設定),
        {
            ユーザー名: gblCurrentUser.displayName,
            ユーザーUPN: gblCurrentUser.userPrincipalName,
            チーム名: cmbTeamName.Selected.displayName,
            チームID: cmbTeamName.Selected.id,
            チャネル名: cmbChannelName.Selected.displayName,
            チャネルID: cmbChannelName.Selected.id
        }
    ),
    Patch(
        通知先設定,
        First(colMySetting),
        {
            ユーザー名: gblCurrentUser.displayName,
            ユーザーUPN: gblCurrentUser.userPrincipalName,
            チーム名: cmbTeamName.Selected.displayName,
            チームID: cmbTeamName.Selected.id,
            チャネル名: cmbChannelName.Selected.displayName,
            チャネルID: cmbChannelName.Selected.id
        }
    );
    
);
If(
     // エラー判定
    !IsEmpty(Errors(通知先設定)),
     // エラーメッセージ
    Notify(
        Concat(
            Errors(通知先設定),
            Column & ": " & Message
        ),
        NotificationType.Error
    ),
     // 成功メッセージ
    Notify(
        "通知先の登録処理が成功しました",
        NotificationType.Success
    );
    ClearCollect(
        colMySetting,
        LookUp(
            通知先設定,
            ユーザーUPN = gblCurrentUser.userPrincipalName
        );
    );
    
);

これにより、以下のようなデータが登録されます。

image.png

登録した通知先を利用する

Power Automate 側

Power Automate 側はシンプルです。Power Apps から、通知先のチームの ID やチャネルの ID を受け取るよう引数を設定し、そちらを利用して Teams のチャネルに投稿をするようにします。

image.png

Power Apps 側

Power Apps 側で以下のボタンを押した際の処理です。

image.png

Patch(
    勤務状況シェア,
    Defaults(勤務状況シェア),
    {
        日付:Today(),
        ユーザー名: gblCurrentUser.displayName,
        ユーザーメールアドレス: gblCurrentUser.mail,
        働き方: drpPlan.Selected.Value,
        一言: txtMemo.Text,
        スケジュール詳細: rteSheduleDetail.HtmlText
    }
);
UpdateContext(
    {
        locFlowResult: M_勤務状況シェアフロー.Run(
            Text(drpPlan.Selected.Value),
            txtMemo.Text,
            rteSheduleDetail.HtmlText,
            Today(),
            First(colMySetting).チームID,
            First(colMySetting).チャネルID
        )
    }
);
If(
    locFlowResult.result = "0",
    Notify(
        "勤務状況の共有処理が成功しました",
        NotificationType.Success
    );
    Set(
        gblCopyData,
        Blank()
    );
    Reset(drpPlan);
    Reset(txtMemo);
    ,
    Notify(
        "勤務状況の共有処理が失敗しました",
        NotificationType.Error
    );
    
);

上記では、アプリで使用するデータソースにもデータを登録するなどの処理が含まれていますが、Power Automate との連携部分は以下です。

UpdateContext(
    {
        locFlowResult: M_勤務状況シェアフロー.Run(
            Text(drpPlan.Selected.Value),
            txtMemo.Text,
            rteSheduleDetail.HtmlText,
            Today(),
            First(colMySetting).チームID,
            First(colMySetting).チャネルID
        )
    }
);

事前に、登録している Teams 通知先の設定情報を以下のような感じで読み込んでおき、その情報を Power Automate に渡しています。

  ClearCollect(
        colMySetting,
        LookUp(
            通知先設定,
            ユーザーUPN = gblCurrentUser.userPrincipalName
        );
    );
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?