Office365-rest-python-client: 単一のリストアイテムを更新するにはどうすればよいですか?

作成日 2018年05月10日  ·  4コメント  ·  ソース: vgrem/Office365-REST-Python-Client

SharePointlistitem.pyの更新メソッドを使用しています
item_object.update()
しかし、更新したいデータをどのように配置できますか? 例えば:
item_properties = {'__metadata':{'type': 'SP.Data。' + listTitle + 'ListItem'}、
'タイトル': '新しいアイテム'、
「値」:99、
}
次に、アイテムを更新します...

question

最も参考になるコメント

前の例は私には機能しません-実際の更新なしで204の応答コードを取得しました。
正しい方法-メソッドを介してオブジェクトのプロパティを設定します。

# Open list object from portal
ctx_auth = AuthenticationContext(url=sharepoint_site_url)
ctx = ClientContext(sharepoint_site_url, ctx_auth)
target_list = ctx.web.lists.get_by_title(sharepoint_root_folder_name)

# Fetch list item object by id and set it's properties
item = target_list.get_item_by_id(item_id)
item.set_property('Title', 'new-title')
item.set_property('NewItem', '99')

# Update list item object and send request back to portal
item.update()
ctx.execute_query()

全てのコメント4件

私が正しく理解している場合は、Sharepointと既に同期されているオブジェクトを更新する必要があります。 これが私がそれを達成した方法です:

    ctx_auth = AuthenticationContext(url=sharepoint_site_url)
    ctx = ClientContext(sharepoint_site_url, ctx_auth)
    target_list = ctx.web.lists.get_by_title(sharepoint_root_folder_name)

    # Fetch item by id and add properties to it.
    item = target_list.get_item_by_id(item_id)
    item.properties.update({
        "NewItem": "99"
    })
    item.update()
    ctx.execute_query()

前の例は私には機能しません-実際の更新なしで204の応答コードを取得しました。
正しい方法-メソッドを介してオブジェクトのプロパティを設定します。

# Open list object from portal
ctx_auth = AuthenticationContext(url=sharepoint_site_url)
ctx = ClientContext(sharepoint_site_url, ctx_auth)
target_list = ctx.web.lists.get_by_title(sharepoint_root_folder_name)

# Fetch list item object by id and set it's properties
item = target_list.get_item_by_id(item_id)
item.set_property('Title', 'new-title')
item.set_property('NewItem', '99')

# Update list item object and send request back to portal
item.update()
ctx.execute_query()

#146で解決

それらの例をありがとう!
決議されたので閉鎖することを提案します。

このページは役に立ちましたか?
0 / 5 - 0 評価