rksoftware

Visual Studio とか C# とかが好きです

Power Automate で SharePoint リストをコピーする

Power Automate で SharePoint リストをコピーする方法です。
今回はまだ不完全で、リストを作って元のリストから列を作ってアイテムをコピーするだけです。例えばビューなどはコピーできていません。

この記事では、 saitamalist0001 という表示名 埼玉0001 リストを別のサイトへコピーしています。

■ 全体像

こんな感じです。簡単そうですね。

■ 設定値

定数 ( アクション | JSON の解析 )

コンテンツ

{
    "site_src": "https://XXXXXXXXXXXXXXXX.sharepoint.com/",
    "site_dest": "https://XXXXXXXXXXXXXXXX.sharepoint.com/sites/teamsite001/",
    "list": "saitamalist0001"
}

スキーマ

{
    "type": "object",
    "properties": {
        "site_src": {
            "type": "string"
        },
        "site_dest": {
            "type": "string"
        },
        "list": {
            "type": "string"
        }
    }
}

リスト削除 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_dest']
方式 POST
URI _api/web/lists/GetByTitle('埼玉0001')
ヘッダー
X-HTTP-Method: DELETE
If-Match: *

SharePoint に HTTP 要求を送信 コピー元取得 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_src']
方式 GET
URI _api/web/lists/GetByTitle('@{body('定数')?['list']}')

SharePoint に HTTP 要求を送信します リスト作成 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_dest']
方式 POST
URI _api/web/lists/
ボディ

@{
    setProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    body('SharePoint_に_HTTP_要求を送信_コピー元取得')?['d'], '__metadata')
    , 'FirstUniqueAncestorSecurableObject')
    , 'RoleAssignments')
    , 'Author')
    , 'ContentTypes')
    , 'CreatablesInfo')
    , 'DefaultView')
    , 'DescriptionResource')
    , 'EventReceivers')
    , 'Fields')
    , 'Forms')
    , 'InformationRightsManagementSettings')
    , 'Items')
    , 'ParentWeb')
    , 'RootFolder')
    , 'Subscriptions')
    , 'TitleResource')
    , 'UserCustomActions')
    , 'VersionPolicies')
    , 'Views')
    , 'WorkflowAssociations')
    , 'CurrentChangeToken')
    , 'ImagePath')
    , 'MajorWithMinorVersionsLimit')
    , 'ParentWebPath')
    , 'Title'
    , 'saitamalist0001')
}

SharePoint に HTTP 要求を送信します リスト名変更 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_dest']
方式 POST
URI _api/web/lists/GetByTitle('@{body('定数')?['list']}')
ヘッダー
X-HTTP-Method: MERGE
If-Match: * ボディ

{'Title':  '@{body('SharePoint_に_HTTP_要求を送信_コピー元取得')?['d']?['Title']}'}

SharePoint に HTTP 要求を送信します コピー元列取得 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_src']
方式 GET
URI _api/web/lists/GetByTitle('@{body('定数')?['list']}')/Fields?$filter=Hidden eq false and ReadOnlyField eq false and Group ne '_Hidden' and StaticName ne 'Title' and StaticName ne 'Attachments'

列のループ ( アクション | それぞれに適用する )

以前の手順から出力を選択 @{body('SharePoint_に_HTTP_要求を送信します_コピー元列取得')?['d']?['results']}

SharePoint に HTTP 要求を送信します 列作成 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_dest']
方式 POST
URI _api/web/lists/GetByTitle('@{body('SharePoint_に_HTTP_要求を送信_コピー元取得')?['d']?['Title']}')/Fields
ボディ

@{
    setProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
        items('列のループ')
    , '__metadata')
    , 'DescriptionResource')
    , 'TitleResource')
    , 'MaxLength')
    , 'DateTimeCalendarType')
    , 'DateFormat')
    , 'DisplayFormat')
    , 'FriendlyDisplayFormat')
    , 'TimeFormat')
    , 'CommaSeparator')
    , 'CustomUnitName')
    , 'CustomUnitOnRight')
    , 'MaximumValue')
    , 'MinimumValue')
    , 'ShowAsPercentage')
    , 'Unit')
    , 'Title', items('列のループ')?['StaticName'
    ])
}

SharePoint に HTTP 要求を送信します 列名変更 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_dest']
方式 POST
URI _api/web/lists/GetByTitle('@{body('SharePoint_に_HTTP_要求を送信_コピー元取得')?['d']?['Title']}')/fields/GetByTitle('@{items('列のループ')?['StaticName']}')
ヘッダー
X-HTTP-Method: MERGE
ボディ

{'Title': '@{items('列のループ')?['Title']}'}

SharePoint に HTTP 要求を送信します コピー元アイテム取得 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_src']
方式 GET
URI _api/web/lists/GetByTitle('@{body('定数')?['list']}')/Items

アイテムのループ ( アクション | それぞれに適用する )

以前の手順から出力を選択 @{body('SharePoint_に_HTTP_要求を送信します_コピー元アイテム取得')?['d']?['results']}

SharePoint に HTTP 要求を送信します アイテム作成 ( アクション | SharePoint に HTTP 要求を送信 )

サイトのアドレス @body('定数')?['site_dest']
方式 POST
URI _api/web/lists/GetByTitle('@{body('SharePoint_に_HTTP_要求を送信_コピー元取得')?['d']?['Title']}')/Items
ボディ

@{
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
    removeProperty(
  items('アイテムのループ')
  , '__metadata')
  , 'FirstUniqueAncestorSecurableObject')
  , 'RoleAssignments')
  , 'AttachmentFiles')
  , 'ContentType')
  , 'GetDlpPolicyTip')
  , 'FieldValuesAsHtml')
  , 'FieldValuesAsText')
  , 'FieldValuesForEdit')
  , 'File')
  , 'Folder')
  , 'LikedByInformation')
  , 'ParentList')
  , 'Properties')
  , 'Versions')
  , 'FileSystemObjectType')
  , 'Id')
  , 'ServerRedirectedEmbedUri')
  , 'ServerRedirectedEmbedUrl')
  , 'ContentTypeId')
  , 'OData__ColorTag')
  , 'ComplianceAssetId')
  , 'ID')
  , 'OData__UIVersionString')
  , 'Attachments')
  , 'GUID')
}

簡単ですね

簡単ですね