Hi @vgrem @Toilal,
I was looking to your code and trying to figure out a code that create a new line in a sharepoint list adding the "request id" string and its attachment file.
This is what I need to do:
As the red arrows shows I need to add the "REQUEST_ID" string and add the "Attachments" file.
I saw some code to upload file but did not find anything related to attachments.
Any help is very welcome!
TKS
Greetings @libora6 ,
here is a generic example which demonstrates how to:
ctx = ClientContext(site_url).with_credentials(ClientCredential(client_id, client_secret))
list_object = ctx.web.lists.get_by_title(list_title)
# 1. create a list item first
new_item = list_object.add_item({
"Title": "Task 123"
}).execute_query()
# 2. upload attachment into list item
with open(attachment_path, 'rb') as content_file:
file_content = content_file.read()
attachment_file_name = os.path.basename(attachment_path)
attachment_file_information = AttachmentfileCreationInformation(attachment_file_name, file_content)
attachment_file = new_item.attachmentFiles.add(attachment_file_information).execute_query()
Notes:
Title
is specified for list item, in your case make sure to specify proper name for field REQUEST_ID
Result
@vgrem tks for your prompt support.