我正在使用 SharePoint listitem.py 的更新方法
item_object.update()
但是我如何放置我想要更新的数据? 例如:
item_properties = {'__metadata': {'type': 'SP.Data.'+listTitle+'ListItem'},
'标题':'新项目',
'价值':99,
}
然后更新项目...
如果我理解正确,您想更新已与 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
谢谢你的例子!
我建议关闭它,因为它已经解决了。
最有用的评论
上一个示例对我不起作用 - 得到 204 响应代码而没有实际更新。
正确的方法 - 通过方法设置对象属性: