Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update a single list item? #72

Closed
continda opened this issue May 10, 2018 · 4 comments
Closed

How to update a single list item? #72

continda opened this issue May 10, 2018 · 4 comments
Labels

Comments

@continda
Copy link

I am using the update method of SharePoint listitem.py
item_object.update()
but how can I put the data I want to update? for instance:
item_properties = {'__metadata': {'type': 'SP.Data.'+listTitle+'ListItem'},
'Title': 'new item',
'Value':99,
}
and then update the item...

@vgrem vgrem added the question label May 11, 2018
@reachtoakhtar
Copy link

If I understand correctly, you want to update an object already synced with Sharepoint. Here's how I achieved it:

    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()

@eperegudov
Copy link
Contributor

eperegudov commented Nov 21, 2019

Previous example not works for me - got 204 response code without actual update.
The right way - set object properties via method:

# 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()

@eperegudov
Copy link
Contributor

Resolved with #146

@vgrem
Copy link
Owner

vgrem commented Nov 26, 2019

Thanks for those examples!
I propose to close it since was resolved.

@vgrem vgrem closed this as completed Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants