Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

System update Author in SharePoint List

Open TobiasObton opened this issue 3 years ago • 2 comments

Hi

First of all, thanks for this great library which has helped me a lot so far!

I am trying to set the Created By / Author of a file/list item. I have followed the example here: https://github.com/vgrem/Office365-REST-Python-Client/blob/master/examples/sharepoint/listitems/system_update_item.py

This is my code:

ctx = ClientContext(site_url).with_credentials(client_credentials) list = ctx.web.lists.get_by_title("DropOff") item = list.get_item_by_id(2834) author = ctx.web.site_users.get_by_email("[email protected]") modified_date = datetime.utcnow()

result = item.validate_update_list_item({ "Title": "Test", "Author": FieldUserValue.from_user(author), "Modified": modified_date }, dates_in_utc=True ).execute_query()

I get this error:

Exception has occurred: TypeError validate_update_list_item() got an unexpected keyword argument 'dates_in_utc'

I have also tried to remove "dates_in_utc" and add "new_document_update=True" instead (I have also tried to set it to False):

ctx = ClientContext(site_url).with_credentials(client_credentials) list = ctx.web.lists.get_by_title("DropOff") item = list.get_item_by_id(2834) author = ctx.web.site_users.get_by_email("[email protected]") modified_date = datetime.utcnow()

result = item.validate_update_list_item({ "Title": "Test", "Author": FieldUserValue.from_user(author), "Modified": modified_date }, new_document_update=True ).execute_query()

This gives me this error:

Exception has occurred: TypeError Object of type FieldUserValue is not JSON serializable

Can anyone please tell me what I am doing wrong or if there is an alternative way to set the Created By / Author of an item?

Best regards, Tobias

TobiasObton avatar May 31 '22 13:05 TobiasObton

Greetings,

good to know you found the library useful :)

Regarding the errors, most likely they occur since outdated version of library is utilized, at least dates_in_utc parameter has been introduced in the recent release (2.3.12)

Anyway would suggest to upgrade to the latest one and the provided errors should no longer occur

image

vgrem avatar Jun 01 '22 17:06 vgrem

Hi vgrem,

Thanks for your quick reply!

I have just upgraded to 2.3.12. Now I don't get the error anymore, and I can see the document is modified as shown in the below picture, but the Author/Created By is not changed.

image (Version 13 is made with the set_property function)

Do you have an idea what the issue might be? Is it because it is a document library?

Best regards, Tobias

TobiasObton avatar Jun 01 '22 17:06 TobiasObton

Although this is an old post, but if someone stumble upon this issue, try also specify dates_in_utc=True to ensure dates are specified in UTC format.

Example: system_update.py

vgrem avatar Feb 25 '24 09:02 vgrem

@TobiasObton , did you ever get the Author field not setting sorted out? I'm having similar issues right now, I cannot change Author/Editor fields at all.

jussihi avatar Apr 09 '24 09:04 jussihi