cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Create a file with a word template

Hi all, 

I would like to create a flow : when an item is created in a list, create a file in a Sharepoint Library with the items from the list. The file is actually a word template document (a custom content type). The problem is that the word document say error when I want to open it. 

Could you help me ? Do you have another solution ?  

flow1.PNGflow2.PNG

 

Thank you, 

Martin

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Anonymous,

 

Within the "Create file" action within your flow, the File Content field is required to fill an binary data, but you filled a String within it.

 

More details about the "Create file" action of SharePoint list, please check the following article:

Create file action

 

I have made a test on my side and please take a try with the following workaround:

  • Add a "When an item is created" trigger, specify Site Address and List Name.
  • Add a "Compose" action, Inputs set to following json data:17.JPG

     

  • Add a "Create HTML table" action, From set to following formula:

    array(outputs('Compose'))
  • Add a "Create file" action, File Content field set to output of "Create HTML table" action, File Name field set to following formula:

    First Name Dynamic content Last Name Dynamic content .doc

     

Note: File Name ends with .doc rather than .docx within File Name field of "Create file" action.

 

Image reference:18.JPG

The flow works successfully as below:19.JPG

The created file opened successfully in my SharePoint library as below:20.JPG

 

 

 

Best regards,

Kris

 

 

 

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

13 REPLIES 13

It is easier to create a document by getting the content using a Get file content action.

GetFileContent.png

This now gives you Word (or whatever format the tmeplate file is that is referenced in the identfier) formatted file content.

 

Then using the Create File action you can create a fiel wherever you like.

Anonymous
Not applicable

Thanks for your help. 
Unfortunately, the Word error is the same

flow3.PNG

Hi Martin,

 

Are you able to open the document that you are using as a source within Office Online without the error message appearing?

Anonymous
Not applicable

Yes, and when I create a new document in the library it opens correctly. If I fill in the item properties manually the Word Document accepts the fields.

I modified the File identifier (I don't really know what I'm doing but I try to find a solution). If I chose my template document for the file identifier, it opens correctly in the library but the list fiels aren't copied.

 

flow4.PNGflow5.PNG

You document lives in the Forms/Content type folder. 

 

Can you try moving your template document into the document library itself and then copy it from there.

Anonymous
Not applicable

I added a "Update File Properties" action and the fields from the list are now copied.

 

I moved the template into the document library itself : the document created is a copy of the template but doesn't take the item fields in consideration. Even if I do it manually.

Hi @Anonymous,

 

That sounds like a content type issue to me. 

 

Does the ocntent type where you copy the document from match the content type where you copy it to? Are the fields identical in both librasries ( i.e. are you using site collection columns?)

Anonymous
Not applicable

Thanks for your answers.

I finally did it thanks to SharePoint Designer.
I followed this article : https://sharepointlibrarian.com/2016/09/30/sp-workflow-to-create-a-document/

 

v-xida-msft
Community Support
Community Support

Hi @Anonymous,

 

Within the "Create file" action within your flow, the File Content field is required to fill an binary data, but you filled a String within it.

 

More details about the "Create file" action of SharePoint list, please check the following article:

Create file action

 

I have made a test on my side and please take a try with the following workaround:

  • Add a "When an item is created" trigger, specify Site Address and List Name.
  • Add a "Compose" action, Inputs set to following json data:17.JPG

     

  • Add a "Create HTML table" action, From set to following formula:

    array(outputs('Compose'))
  • Add a "Create file" action, File Content field set to output of "Create HTML table" action, File Name field set to following formula:

    First Name Dynamic content Last Name Dynamic content .doc

     

Note: File Name ends with .doc rather than .docx within File Name field of "Create file" action.

 

Image reference:18.JPG

The flow works successfully as below:19.JPG

The created file opened successfully in my SharePoint library as below:20.JPG

 

 

 

Best regards,

Kris

 

 

 

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Thank you !! It works

I was able to achieve it in Microsoft Flow. See my post here:

 

http://www.sharepointcorridor.com/2018/05/generate-word-document-from-sharepoint.html 

danmitchell36
Resolver II
Resolver II

@Anonymous ,

 

This can now be done in a much easier way using the Microsoft Word connectors.

 

Check out the blog below:

 

https://www.dmcinfo.com/latest-thinking/blog/id/9838/overview-of-microsoft-flows-new-word-online-connectors

I followed this answer and it does generate files with a .doc extension, however they are encoded as HTML files (due to the use of HTML table). Attempting to preview or open them in anything other than Word itself (such as uploading the doc file to Google Drive) fill cause it to just behave as raw HTML. In my workflow, I needed to use the files this way, so this answer doesn't solve it for me. 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors
Users online (1,116)