技術情報ブログ
Power Platform
2023.11.01

Power Automate×SharePoint:SharePoint上からPower Automateを実行する方法

Power Automate×SharePoint:SharePoint上からPower Automateを実行する方法
小刀稱知哉

こんにちは。アーティサン株式会社の小刀稱(ことね)です。

皆さん、SharePoint上からPower Automateを実行する方法をご存知ですか?

標準であれば、SharePointリストやライブラリのアイテム横の3点リーダー自動化対象のフロー名(以下では「データのコピー」という名前) を選択することで、Power Automateを実行できます。

SharePoint上でPower Automateを実行(標準)
SharePoint上でPower Automateを実行(標準)

しかし上記の方法では、フローを実行するまでの手順が多いため、フローの存在を知らない人は実行することが難しいのではないでしょうか。

そこで、今回は小ネタとしてSharePointリストにボタンを配置し、ボタン押下時にPower Automateを実行する方法について紹介します。

 

やりたいこと

今回はSharePointリスト上にボタンを配置します。
そしてそのボタンを押下すると、値をコピーするPower Automateを実行する機能を実装します。

イメージは以下です。

SharePointリストのボタンを押下するとPower Automateを実行
SharePointリストのボタンを押下するとPower Automateを実行

 

実装方法

実装の手順は以下のとおりです。

 

Power Automateの作成

まずは、Power Automateの作成です。

内容としては選択したアイテムの値をコピーする機能を実装しています。
また詳細は割愛しますが、トリガーとしては選択したアイテムの場合を使用しています。

作成したフローは以下です。

作成したPower Automate
作成したPower Automate

 

Power AutomateのGUIDを取得

続いて、作成したPower AutomateのGUIDを取得します。

先程のPower Automateの詳細画面に遷移してください。
本画面のURL部分にGUIDに含まれています。

(以下赤字部分がGUIDです。)
https://make.powerautomate.com/environments/Default-xxxxxxxxxxxx/flows/c14cde3b-8755-4e9c-8d2b-70d0914c83f8/details

フローのGUID
フローのGUID

 

SharePointの書式設定でボタンを作成

それでは、SharePointリスト上にボタンを作成し、Power Automateを実行できるようにしましょう。
こちらではJSONを用いてボタンを作成します。

手順は以下です。

  • 新しい列(1行テキスト)を作成(※今回は「フロー実行」という列名で作成)

  • 「この列の書式設定」 → 詳細モード からJSONを記載する画面を表示

  • 以下のJSONを記載

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "値のコピー",
  "customRowAction": {
  	"action": "executeFlow",
  	"actionParams": "{\"id\": \"c14cde3b-8755-4e9c-8d2b-70d0914c83f8\"}"
  }
}
作成したJSON
作成したJSON

ポイントとしては、上記の赤字部分に先程取得したPower AutomateのGUIDを指定することです。

これにより、ボタンを押下すると指定されたPower Automateが実行されるようになります。

SharePointリストのボタンを押下するとPower Automateを実行
SharePointリストのボタンを押下するとPower Automateを実行

 

Power Automateの権限設定

上記までの手順で、機能の実装は完了です。

最後にPower Automateを共有することで、フローにアクセス許可を与えてください。
※実行権限が与えられていないユーザーは、「ボタンが見えているが、押下しても何も反応しない」という状態となります。

共有に関する詳細については、以下URLを参照してください。
クラウド フローを共有する

 

補足:ボタンのデザインを変更したい

先程作成したボタンはデザインを何も設定していないので、簡素なデザインになっています。

JSONを活用することで、きれいなボタンを作成することも可能ですので、挑戦してみてください!
(HTML To Formatterを用いると、HTMLやCSSをJSONに変換することを手助けしてくれます。)
HTML To Formatter

 

ボタンのサンプル1(リッチなデザイン)

以下では、デザインをリッチにしたサンプルボタンを紹介します。

ボタンサンプル1
ボタンサンプル1

JSONは以下のとおりです。

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "width": "100%",
    "height": "100%",
    "position": "absolute",
    "margin": "auto"
  },
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\":   \"<Flow ID>\"}"
      },
      "style": {
        "border": "solid 1px #ffffff",
        "border-radius": "55px",
        "display": "flex",
        "justify-content": "center",
        "align-items": "center",
        "padding": "6px 15px",
        "margin": "0 auto"
      },
      "attributes": {
        "class": "ms-bgColor-communicationPrimary ms-bgColor-communicationShade20--hover ms-fontColor-white"
      },
      "children": [
        {
          "elmType": "span",
          "style": {
            "margin-right": "10px"
          },
          "attributes": {
            "iconName": "Copy"
          }
        },
        {
          "elmType": "span",
          "txtContent": "値のコピー"
        }
      ]
    }
  ]
}

 

ボタンのサンプル2(ステータスに応じて、ボタンのデザインを変更)

下では、ステータス列の値に応じて、ボタンのデザインを変更しています。

ボタンサンプル2
ボタンサンプル2

JSONは以下のとおりです。

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "width": "100%",
    "height": "100%",
    "position": "absolute",
    "margin": "auto"
  },
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"<Flow ID>\"}"
      },
      "style": {
        "border": "solid 1px #ffffff",
        "border-radius": "55px",
        "display": "=if([$Status]=='申請中', 'flex', 'none')",
        "justify-content": "center",
        "align-items": "center",
        "padding": "6px 15px",
        "margin": "0 auto"
      },
      "attributes": {
        "class": "ms-bgColor-communicationPrimary ms-bgColor-communicationShade20--hover ms-fontColor-white"
      },
      "children": [
        {
          "elmType": "span",
          "style": {
            "margin-right": "10px"
          },
          "attributes": {
            "iconName": "Warning"
          }
        },
        {
          "elmType": "span",
          "txtContent": "承認する"
        }
      ]
    },
    {
      "elmType": "button",
      "style": {
        "border": "solid 1px #ffffff",
        "border-radius": "55px",
        "display": "=if([$Status]!='申請中','','none')",
        "justify-content": "center",
        "align-items": "center",
        "padding": "6px 15px",
        "margin": "0 auto"
      },
      "attributes": {
        "class": "ms-bgColor-gray40 ms-fontColor-white"
      },
      "children": [
        {
          "elmType": "span",
          "style": {
            "margin-right": "10px"
          },
          "attributes": {
            "iconName": "Like"
          }
        },
        {
          "elmType": "span",
          "txtContent": "承認済"
        }
      ]
    }
  ]
}

 

おわりに

今回は、小ネタとしてSharePointリストにボタンを配置し、ボタン押下時にPower Automateを実行する方法について紹介しました。

JSONを使いこなすことができるとSharePointの表現の幅が拡がるので、ぜひ覚えていただきたい内容です。
(実は、X-SP | SharePoint デザイン・機能拡張サービスもJSONを活用することで実装していたりします(笑))

最後まで読んでいただき、ありがとうございました!

Power Platform(SharePoint・Power Apps・Power Automate)に関する営業活動や設計、開発などを担当:小刀稱知哉

小刀稱知哉

大分県出身(温泉大好き♥♥)、現在は東京都在住

1990年4月9日生まれ

30才にしてメーカーの技術営業からIT業界にジョブチェンジ!!!

趣味は読書

Power Platform(SharePoint・Power Apps・Power Automate)に関する営業活動や設計、開発などを担当しております!

シェアする
記事カテゴリ
最新記事
2024.04.17

Power Apps・Power Automateの勉強方法(1)

2024.04.03

非エンジニア【(元)自治体職員】が半年間ローコード開発をしてみたら

2024.03.27

Power Automateのベストプラクティス・アンチパターン(5)【Apply to each×コンカレンシー×変数の設定はNG】

2024.03.20

Power Apps×Teams:Teams上からPower Appsを実行する方法

2024.03.13

Power Apps:SharePointリストと連携したカレンダーアプリを自作してみよう

モデル駆動型アプリPower AppsPower PlatformSharePointExcelPower AutomateC#attributevalidationローコードAngularAccessInfoPathMatTableAngular Materialデータ構造SortByColumns関数TypeScriptHTMLEF CoreマイグレーションFramework CoreAttribute directivesO/Rマッパーazure sql databaseCase式HTTP RequestCSSxUnit.Net Core 3.1VSCode.Net Core Test ExplorerDataverse for Teamsitem関数Google MapsMarker ClustererRANK()関数Dynamics 365 SalesMicrosoft TranslatorマーカークラスタリングライブラリtailwindcssマルチテナントドロップダウンメニューBreakpointObserverメディアクエリスマホPCレスポンシブ入門初心者中級者キャンバスアプリDatePickerDropdownviewビューアクセス制限承認リマインドSetForAllUpdateContextロードマップ技術It情報技術メッセージIDメールfirst()関数nest入れ子動的リストcollectionコレクション複数の添付ファイル承認フローformエクスポートインポートカスタマイズcomponentダイアログコンポーネントdialogTips新機能変数検索Microsoft 365グループセキュリティグループ送信元メールの送信差出人インスタントクラウドフロー自動化したクラウドフロー委任VBAエラーエクセルerror復元restorePower BI個人列ユーザー列SharePoint Onlineリスト非表示アプリ[市民開発者構築自動化したクラウド フローフローの種類インスタント クラウド フロースケジュール済みクラウド フローレスポンシブ レイアウトresponsive layoutデータ行の制限引き継ぎ退職所有者を変更異動LoopMicrosoftdesignJSONデザインtemplateテンプレート運用選択肢列参照列ChatGPTOpenAIオープンAIチャットGPTgalleryギャラリースクロールコンテナショートカットキーshortcut keyconcat関数文字制限フロー実行開発環境環境本番環境ライセンス環境構築手順pipelineCI/CDパイプラインDevOpsMicrosoft 365簡易在庫管理時間外通知ファイルフィルター クエリドキュメント ライブラリfilter querysortソートmultiple item複数項目シェアポイント便利機能カレンダーCalendarTeamsローコード開発非エンジニア体験談勉強内製化
PageTop
ページトップに戻る