Office365-rest-python-client: Wie aktualisiere ich ein einzelnes Listenelement?

Erstellt am 10. Mai 2018  ·  4Kommentare  ·  Quelle: vgrem/Office365-REST-Python-Client

Ich verwende die Aktualisierungsmethode von SharePoint listitem.py
item_object.update()
aber wie kann ich die Daten eingeben, die ich aktualisieren möchte? zum Beispiel:
item_properties = {'__metadata': {'type': 'SP.Data.'+listTitle+'ListItem'},
'Titel': 'Neuer Artikel',
'Wert':99,
}
und aktualisiere dann den Artikel...

question

Hilfreichster Kommentar

Vorheriges Beispiel funktioniert bei mir nicht - Antwortcode 204 ohne tatsächliches Update erhalten.
Der richtige Weg - Objekteigenschaften per Methode setzen:

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

Alle 4 Kommentare

Wenn ich das richtig verstanden habe, möchten Sie ein bereits mit Sharepoint synchronisiertes Objekt aktualisieren. So habe ich es erreicht:

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

Vorheriges Beispiel funktioniert bei mir nicht - Antwortcode 204 ohne tatsächliches Update erhalten.
Der richtige Weg - Objekteigenschaften per Methode setzen:

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

Gelöst mit #146

Danke für diese Beispiele!
Ich schlage vor, es zu schließen, da es gelöst wurde.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

ahulist picture ahulist  ·  5Kommentare

Mark531 picture Mark531  ·  11Kommentare

BradshawI picture BradshawI  ·  5Kommentare

etiennecelery picture etiennecelery  ·  4Kommentare

oktorok picture oktorok  ·  5Kommentare