0
0

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 1 year has passed since last update.

PAD: SharePoint Lists への SQL を利用した User 追加や更新時は、SiteUsers の Id を利用する

Last updated at Posted at 2023-02-15

背景

会社で、User 追加でエラーになるって話だったので、たぶん SiteUsers 使えばいいんじゃない?って思ったけど余裕が無かったので、自宅で検証した記録

結論

SiteUsers の Id で更新も追加も出来ました。

テナントの User Id を使って更新・追加しようとしてしまうんですが・・
SharePoint のサイトごとにある User ID を利用する必要があるっていうオチですね。

昔、Teams メンバー一覧リストを作った際の知見が役に立ちました :laughing:

詳細

そもそもの SQL 操作は以下で確認を

困る部分としての説明のみ

以下 API を使って、SiteUser ID を取得します

{SharePoint Site URL}/_api/Web/SiteUsers

例
https://***.sharepoint.com/sites/testsite/_api/Web/SiteUsers

一覧としては、{SharePoint Site URL}/_catalogs/users で見られるんですが、ID を取る方法はやっぱりAPIかな

これで取得出来るのは xml 形式で、
image.png
こんな感じで、各ユーザー毎の Id が格納されています。

ということで、あとは、この Id を PAD の Insert Statement に設定してやれば OK

image.png

で、実行結果は以下
無事目的のユーザーで更新出来てますね。
image.png

あとは頑張って自動化してください。

更新の場合の例

ユーザ列を更新しないと、上手くいかない、という話があったので試してみた

ユーザー列自体の更新
UPDATE  list SET usr = 9 WHERE Title = 'shima_kuma'
ユーザー列を更新しない場合
UPDATE  list SET RawA = '×' WHERE Title = 'shima_kuma'

上記で、以下もOK

  1. ユーザー列を更新
  2. 〇⇒×へ更新:ユーザ列を非糠疹

image.png

同一のユーザ情報を別の列で参照してる・・とか・・かな?

かと思って、ユーザー列を参照して、substring() を利用した列を追加してみたが、特に問題なく更新出来た。
状況を聞いてみないとこれ以上はわからないね。

image.png

コンテンツタイプを有効にしても変わらず

image.png

ドキュメント

目的 API Doc
Site の user 一覧 _api/Web/SiteUsers SPWeb.SiteUsers Property

# あとがき
ROS2 の勉強しないとなんだけど・・やる気が起きないので、ついつい横道へ・・ :cry:

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?