0
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?

【Power Apps】URL パラメーターを指定して SharePoint リストアイテムを表示する

Last updated at Posted at 2023-03-16

【Power Apps】URL パラメーターを指定して SharePoint リストアイテムを表示する

URL パラメーターに SharePoint カスタムリストのアイテム ID を指定し、Power Apps で作成したフォームで表示する方法です。URL パラメーターに指定された値を取得するためには、Param 関数 を使います。

※2024/12 更新
OnStart プロパティを使用しないように修正

準備

SharePoint のカスタムリスト (例では、Announce リスト) でアプリを作成します。

  1. 対象のカスタムリストを表示して、[統合] > [Power Apps] > [アプリの作成] を選択します。
    image.png
  2. 自動でアプリが作成されます。
  3. [名前を付けて保存] をクリックしてアプリを保存します。
    image.png

パラメーターの有無で開くスクリーンを変更する

StartScreen プロパティ

App の StartScreen プロパティを設定します。

URL パラメーターがない場合は、一覧画面 (BrowseScreen1)、パラメーターある場合は、詳細表示画面 (DetailScreen1) が初期表示画面になるように設定します。
image.png

If(
    IsBlank(Param("ID")),
    BrowseScreen1,
    DetailScreen1
)

パラメーターをコンテキスト変数に設定する

OnVisible プロパティ

DetailScreen1 の OnVisible プロパティを設定します。

URL パラメーターがある場合にコンテキスト変数 (_ID) に数値に変換した値を設定します。
image.png

If(
    !IsBlank(Param("ID")),
    UpdateContext({_ID: Value(Param("ID"))})
);

遷移先のコンテキスト変数に設定する

BrowseScreen1 から DetailScreen1 画面への遷移

BrowseGallery1 の OnSelect プロパティの Navigate 関数に、選択しているアイテムの ID を指定して、DetailScreen1 のコンテキスト変数として呼び出せるように渡します。

image.png

Navigate(
    DetailScreen1,
    ScreenTransition.None,
    {_ID: BrowseGallery1.Selected.ID}
);

DetailScreen1 から EditScreen1 画面への遷移

IconEdit1 の OnSelect プロパティの Navigate 関数に、アイテムの ID を指定して、EditScreen1 のコンテキスト変数として呼び出せるように渡します。

image.png

EditForm(EditForm1);
Navigate(
    EditScreen1,
    ScreenTransition.None,
    {_ID: _ID}
);

Form コンポーネントに表示するアイテムを設定する

Item プロパティ

DetailScreen1 の DetailForm1 と EditScreen1 の EditForm1 それぞれの Item プロパティを設定します。

LookUp 関数でアイテムを取得するように設定します。
image.png

LookUp(Announce, ID = _ID)

カスタムリストからアプリのフォームを直接開く

列の書式設定を設定してビューからアイテムの詳細をアプリで開くように設定します。

準備

作成したアプリの [詳細] から Web リンク(URL) を取得しておきます。

列の書式設定

列の書式を設定してアプリが開くように設定します。
image-20230316102317031.png

書式設定

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='https://apps.powerapps.com/play/e/{環境 ID}/a/{アプリID}?tenantId={テナントID}&ID=' + [$ID]"
  }
}

参考サイト

0
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
0
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?