2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Formsの添付ファイルのファイル名からユーザー名を取り除く

Last updated at Posted at 2021-05-24

はじめに

Forms(グループフォーム)でファイルを添付すると、ファイル名が「元のファイル名+アンダーバー+ユーザー名」に変更されて、Sharepointに保存される。
これについて、元のファイル名に戻す(「元のファイル名+アンダーバー+ユーザー名」→「元のファイル名」)方法を考案したので紹介する。
(もっと簡単なやり方があれば、是非教えてください!)

概要

Power Automateを利用する。

使用するトリガー

image.png

使用するアクション

image.png

補足

Formsのコネクターは使用しない。
(Formsの投稿をトリガーにすると、複数ファイルを添付した際の対応を考慮する必要が発生してしまうと考えたため)

アクションの内容補足

配列 filename_username

split(triggerOutputs()?['body/{Name}'],'_')

変数 length of filename_username

length(variables('filename_username'))

length of filename_username - 1

「変数の値を減らす」アクションを選択して、以下の通り入力する。
image.png

配列 filenames

take(
    variables('filename_username'),
    variables('length of filename_username')
    )

変数 filename

join(variables('filenames'),'_')

SharepointにHTTP要求を送信します

完成イメージ

image.png

URI

_api/web/lists/getbytitle('(ライブラリ名)')/items(triggerOutputs()?['body/ID'])
```

### ヘッダー
|  |  |
|:-----------|------------:|
| X-HTTP-Method|MERGE|
|IF-MATCH|*|
|content-type|application/json;odata=verbose|

### ボディ
```
{'__metadata':{'type':'(取得したListItemEntityTypeFullName)'},'FileLeafRef':'@{variables('filename')}'}
```

#### ListItemEntityTypeFullNameの取得方法
以下のURLにアクセスし、表示されたページの`<d:ListItemEntityTypeFullName>`直後の文字列をコピーする

```
https://(sharepointのサイトURL))/_api/web/lists/getbytitle('(ライブラリ名)')?$select=ListItemEntityTypeFullName
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/684495/1f4a074d-ca82-06e2-b239-a393b1c37b90.png)
※デフォルトのドキュメントライブラリを使用する場合は、ライブラリ名の枠に「Documents」と入力する


# 変数関連のアクションでやっていることの全体像
1. アンダーバーを区切り記号として、ファイル名を分割して配列にする
1. 作った配列から、最後の要素のみを取り除く
1. 加工した配列について、アンダーバーを区切り記号として再度結合して文字列にする

# その他ポイント
- トリガーで「ファイルが作成されたとき(プロパティのみ)」を選択する
- アクションで「sharepointにHTTP要求を送信します」を使用する

# 参考にした記事
https://social.technet.microsoft.com/wiki/contents/articles/53731.power-automate-update-file-name-of-sharepoint-document-on-file-upload-using-http-action.aspx

https://docs.microsoft.com/ja-jp/azure/logic-apps/workflow-definition-language-functions-reference
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?