10
4

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 で Patch 関数を利用した際の成功やエラーメッセージ表示

Last updated at Posted at 2023-02-19

はじめに

Power Apps でデータソースにデータの登録を行う際、データの登録処理が成功したか失敗したかによってメッセージを変えたり後続処理を書きたい場合があると思います。

フォーム コントロールを利用する場合は、フォームの OnSuccessOnFailure プロパティに処理を記述するのが一般的と思いますが、今回は、Patch 関数を利用する場合における方法を紹介します。

実装方法

今回は、こちらのイベントで紹介したアプリカタログのソースを元に説明します。

image.png
image.png

本筋とは異なりますが、こんな感じで、Power Apps で作成されたアプリやそのソースをカタログ化しておくと、アプリが見つけやすくなる、アプリへの到達が容易になる、同じようなアプリを一から作成しなくて済むなどのメリットがあります

こちらのアプリのデータ登録処理では、以下のような感じでデータ登録をしています。

Patch(
        アプリカタログ,
        Defaults(アプリカタログ),
        {
            new_environmentid: cmbEnvironment_1.Selected.name,
            new_appid: txtAppId.Text,
            new_appname: txtAppName.Text,
            new_ismanualregister: true,
            new_applink: txtAppLink.Text,
            new_appdescription: txtAppDescription.Text,
            new_creatername: txtAppCreater.Text,
            new_createrdepartment: txtAppCreaterDepartment.Text,
            new_createrupn: txtAppCreaterUPN.Text,
            new_createdate: dteAppCreatedDate.SelectedDate,
            new_appsource: txtAppSourceLink_1.Text,
            new_isshareonlyappsource: tglIsShareOnlyAppSource.Value,
            new_addteamscount: 0,
            new_downloadcount: 0
        }
    );

If(
     // エラー判定
    !IsEmpty(Errors(アプリカタログ)),
     // エラーメッセージ
    Notify(
        Concat(
            Errors(アプリカタログ),
            Column & ": " & Message
        ),
        NotificationType.Error
    ),
     // 成功メッセージ
    Notify(
        "アプリカタログへの登録処理が成功しました",
        NotificationType.Success
    );
);

ポイントは、Errors 関数を利用するところです。Errors 関数についてはこちらを参考になさってください。

10
4
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
10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?