Microsoft Flow - Form, into excel, create word document from template, send email, addressing Copy/Create File errors

Today a customer showed me a paper (invoice) recipe  he had to write into an excel, and then again into a word "thank you" for printing/emailing.

If you're here for the Copy/Create File errors, jump to the end.

So what we did is to prepare a Form for inputs, and then a Flow that takes that data, use "Insert Row" for excel.

Next was to create the word document. I've tried to create custom properties myself, but didn't manage so I followed Netwoven's tutorial, and the simple steps are:

1 - Create a Sharepoint Document Library and add your custom properties to the library as custom Fields.
2 - Go to Library Settings > Advanced Settings > click Edit Template
3 - The template will open an empty word document, edit it however you want
4 - Wherever you want one of the dynamic custom properties to fit in put your cursor there and click Insert > Quick Parts > Document Property > your custom Fields name
5 - Save the document as a normal .docx in your PC folder, upload it to your newfounded SP Library

Next is the flow steps, while the initial steps are easy and seen in this image, the word steps needs a bit more explaination, so let me put here the 2 images, and then talk about them, 1st the flow:

As we can see, taking the data from the form, into the excel, duplicating the file, i chose "Create file" since it enables me to choose the file name.

"Update file properties" is where the magic happens, I map the data to the custom properties so the while opening the file they let themselves in:

Marked in orange is the 2 properties I use for the word, full name and today's date, formatted.
Missing from the image is "formatDateTime( utcNow(), 'dd-MM-yy' )"


At this point, all I should have done to send the file by email was to do again "Get file content" but I got some errors, 400 error, 404 file not found error, sharepoint's 0x80070002 error, ect.

Googling that I found out that duplicating a file, via "Create file" or "Copy file" caused some errors, and while in some posts people suggested to use "Delete file" that wasn't relevant here, and while looking again at Netwoven's tutorial I though to myself that maybe...

I have many years or experience with Sharepoint, for better and worse, and, so I believe, since Sharepoint keeps a version for each file change in the DB, and might have just locked it, therefor using the trigger for the new version, behind the scenes it duplicates again the file contents and properties, so just using the "When file is created or modified in a folder" event trigger solved those problems (as a safety caution, I matched to a very specific folder).

I finally used "File content" from the modified event, and all went well.

Be in touch!


Post a Comment

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

Asp.Net Ending Response options, Response.End() vs CompleteRequest()