LoginSignup
3
4

More than 1 year has passed since last update.

選択したTeamメンバーの一覧をAutomateで作る with SharePoint Rest API

Last updated at Posted at 2021-07-19

何のために?

  • チーム内の管理用Listを作るときに、メンバー全員を入れるのが手作業だと面倒なので
    • Automateを使わないTeamとかもあるけれど、メンバー一覧があると提出記録なんかも記録しやすいよね、と

Source

Zip で共有

動作概要

  1. 起動
    1. Instantなんで、Run Flowか、Flow Editorから
    2. Select for message とかで起動するのもありなんだけど、しょっちゅう使うものでもないしねぇ・・
  2. Automateからチャットが飛んでくる image.png
    1. 新規作成するリスト名を入れる(一応日本語でもOK)
    2. 実行者が所属 or 保有しているTeamの一覧から、追加するTeamを選択
    3. 「これで生成する」を押して生成開始
  3. 後は待つのみ
    image.png
  4. 完了したら、リンクがあるので踏む image.png
  5. こんな感じでListが出来て、中にはメンバーが入ってます
    image.png

Automate のDefault Actionだけでやらなかった理由

  • Team 選んで既存のListに突っ込むとなると、既存のItemとの競合を考える必要があるので面倒。で、Listを新規作成して突っ込もうとしたら・・Default Action だけじゃダメだったのです。今後Rest APIを網羅してくればとは思いますが、どうなんでしょうね。

で、フロー:後日Zipで公開するかも?

image.png
肝っぽいとこだけ一応紹介

追加するTeamの選択

image.png

SelectTeam
{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "msteams": {
        "width": "full"
    },
    "version": "1.2",
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "追加する Lists の名前を入力してください",
                    "wrap": true,
                    "color": "Accent"
                },
                {
                    "type": "Input.Text",
                    "placeholder": "リストの名前",
                    "id": "ListName",
                    "value": "UserNames"
                },
                {
                    "type": "TextBlock",
                    "text": "同一名称があった場合、末尾に数字付加",
                    "wrap": true,
                    "color": "Warning",
                    "spacing": "None",
                    "horizontalAlignment": "Right",
                    "size": "Small",
                    "weight": "Lighter"
                }
            ]
        },
        {
            "type": "Container",
            "separator": true,
            "items": [
                {
                    "type": "TextBlock",
                    "text": "ユーザー一覧を追加したいTeamを選択してください。",
                    "wrap": true,
                    "color": "Accent"
                },
                {
                    "type": "Input.ChoiceSet",
                    "choices": @{outputs('Compose_TeamList')},
                    "placeholder": "Placeholder text",
                    "id": "TeamSelection",
                    "spacing": "None"
                },
                {
                    "type": "TextBlock",
                    "text": "選んだTeams内のListsに追加します。",
                    "wrap": true,
                    "spacing": "None",
                    "horizontalAlignment": "Right",
                    "size": "Small",
                    "weight": "Lighter",
                    "color": "Warning"
                }
            ]
        },
        {
            "type": "ActionSet",
            "actions": [
                {
                    "type": "Action.Submit",
                    "title": "これで生成する",
                    "wrap": true,
                    "style": "positive"
                }
            ]
        }
    ]
}

List新規作成

image.png

CreateList
{
  "__metadata": {
    "type": "SP.List"
  },
  "AllowContentTypes": true,
  "BaseTemplate": 100 ,
  "ContentTypesEnabled": true,
  "Description": "Users List Created By Automate",
  "Title": "@{variables('ListName')}"
}

BaseTemplate の番号は、Site の設定から。お知らせ=104 とか

選択したTeamのメンバー取得

image.png

Listにメンバーを追加

image.png

あとがき

勢いで作ってみたけど、Qiitaじゃ公開しにくいことに気付いた・・GitHub久しぶりに使うかのぉ :thinking:

今回利用した Share Rest API まとめ

目的 api MS Doc 補足
Lists 一覧 _api/web/lists REST を使用してリストとリスト アイテムを操作する
List 取得 by Title _api/web/lists
/getByTitle('{Title}')
対象List の items 一覧 _api/web/lists
/getByTitle('{Title}')/items
対象List の View 一覧 _api/web/lists
/getByTitle('{Title}')/views
View Properties(古い?)
対象List の View 取得 by Title _api/web/lists
/getByTitle('{Title}')/views
/getByTitle('{Title}')
対象List の View の Fileds 一覧 _api/web/lists
/getByTitle('{Title}')/views
/getByTitle('{Title}')/ViewFields
対象List の View の Fileds に Field 追加 _api/web/lists
/getByTitle('{Title}')/views
/getByTitle('{Title}')/ViewFields
/AddViewField
ViewFieldCollection methods
Site の user 一覧 _api/Web/SiteUsers SPWeb.SiteUsers Property UserのGUIDではなく、サイトに紐づいたIDが取得可能。というか、Actionで取る方法は無いのかな?あってもサイト指定になるから面倒かなぁ・・
自分の情報 _api/SP.UserProfiles.PeopleManager
/GetMyProperties
PeopleManager メソッド これで取れない事があれば?
3
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
3
4