addGlobalNotification (クライアント API 参照)

エラー、情報、警告、または成功通知をアプリに表示し、通知に基づいて実行するアクションを指定することができます。

構文

Xrm.App.addGlobalNotification(notification).then(successCallback, errorCallback);

パラメーター

件名 必要な領域 内容
notification オブジェクト あり 追加する通知。 オブジェクトには、次の値が含まれています:
  • action: (オプション) オブジェクト。 以下の値を含みます:
    • actionLabel : (オプション) 文字列。 メッセージ内のアクションのラベル。
    • eventHandler : (オプション) 関数リファレンス。 アクション ボタンがクリックされると実行される関数です。
  • レベル: 番号。 通知のレベルを定義します。 有効な値は:
    • 1: 成功
    • 2: エラー
    • 3: 警告
    • 4: 情報
  • message: 文字列。 通知で表示されるメッセージ。
  • showCloseButton : (オプション) ブール値。 ユーザーが通知を閉じるまたは無視することができるかどうかを示します。 このパラメーターを指定しない場合、ユーザーは既定で通知を閉じることも無視することもできません。
  • 種類: 番号。 通知の種類を定義します。 現在、2 の値のみがサポートされており、アプリの上部にメッセージ バーが表示されます。
successCallback Function 無効

通知が表示された場合に呼び出す関数です。 GUID 値は、通知を一意に識別するために渡されます。 GUID 値を使用し、clearGlobalNotification メソッドを使用して、通知を閉じるか無視することができます。

errorCallback Function 無効 処理が失敗したときに呼び出す関数。

戻り値

成功時には、successCallback パラメーターの説明で前述したように、GUID 値を含む promise オブジェクトを返し、通知を一意に識別します。

ユーザーが閉じることも無視することもできないエラー通知を表示する

// define notification object
var notification = 
{
  type: 2,
  level: 2, //error
  message: "Test error notification"
}

Xrm.App.addGlobalNotification(notification).then(
    function success(result) {
        console.log("Notification created with ID: " + result);
        // perform other operations as required on notification display
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

以下のように、アプリにエラー通知が表示されます。

エラー通知の例。

ユーザーが閉じることも無視することもできない警告通知を表示する

// define notification object
var notification = 
{
  type: 2,
  level: 3, //warning
  message: "Test warning notification",
  showCloseButton: true
}

Xrm.App.addGlobalNotification(notification).then(
    function success(result) {
        console.log("Notification created with ID: " + result);
        // perform other operations as required on notification display
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

以下のように、アプリに警告通知が表示されます。

警告通知の例。

// define action object
var myAction =
{
  actionLabel: "Learn more", 
  eventHandler: function () {
        Xrm.Navigation.openUrl("https://docs.microsoft.com/powerapps/");
        // perform other operations as required on clicking
    }
}

// define notification object
var notification = 
{
  type: 2,
  level: 4, // information
  message: "Test information notification",  
  action: myAction
}

Xrm.App.addGlobalNotification(notification).then(
    function success(result) {
        console.log("Notification created with ID: " + result);
        // perform other operations as required on notification display
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

以下のように、アプリに情報通知が表示されます。

情報通知の例。

関連項目

clearGlobalNotification

注意

ドキュメントの言語設定についてお聞かせください。 簡単な調査を行います。 (この調査は英語です)

この調査には約 7 分かかります。 個人データは収集されません (プライバシー ステートメント)。