How to dynamically create and populate Word Document in a Document Library from Custom List

How to dynamically create and populate Word Document in a Document Library from Custom List

By Supriya Tenany  •  April 24, 2015  •  32423 Views

How to dynamically create and populate Word Document in a Document Library from Custom List

In the context of SP Online or SP 2013, we visualize them to be omnipotent, or if not for this, then atleast have much more vigour than their predecessors. What also bestows to the pool of features is also the availability of the SharePoint Designer (SPD) 2013 workflow. However, a little use of workflows using SPD 2010 also can extend the OOTB capabilities.

Workflows need not just be visualized as a process to flow items or streamlines tasks among users, rather in the simplest form, a workflow can also update data in field.

This article sheds lights on exploiting the capability of SP Online in conjunction with a SPD 2010 workflow to dynamically create documents in a document library.

A SharePoint document library not only acts as a repository for documents, but it can also be used to dynamically generate documents as mentioned before. The process requires coupling the document library with a custom list with the same field definitions as the document library using a workflow and editing the document template to format it using Quick Parts to place fields of the document library.

Though the process is worthwhile to generate documented format of a list containing simple text, there are still some limitations to this way of creation, in the use of embedding pictures or styling text.

The following section details the entire process.

Creating a Custom List for feed

The process is verified to work well only with data of single or multiline text (selected as Plain Text).

For the purpose of demonstration, a simple document library is created with columns of type single and multiline text.

N.B.: In the document library, the Title column of the document library is renamed Member Name.

To feed to this document library, a list is created, with columns mapped to that of the document library.

How to dynamically create and populate Word Document in a Document Library from Custom List

N.B.: In this list, the Title column of the document library is renamed Member Name.

As mentioned earlier, the only restriction with using multiline text is the use of Plain Text as illustrated below.

How to dynamically create and populate Word Document in a Document Library from Custom List

SharePoint Custom Development

Customizing the Document Library

In the document library, go to Settings –> Advanced Settings and in the Document Template section, Edit Template.

How to dynamically create and populate Word Document in a Document Library from Custom List

The template is opened in the default word application. To format the document to use data from the columns of the document library, position the cursor in the document and from the menu, go to Insert –> Quick Parts –> Document Property and select the column.

How to dynamically create and populate Word Document in a Document Library from Custom List

Having formatted this template to place data as desired, save the template in the same location of the document library, but in docx format.

How to dynamically create and populate Word Document in a Document Library from Custom List

Upon exiting from the word application, modify the extension of the document template in the document library to point to the modified template (docx instead of

dotx).

How to dynamically create and populate Word Document in a Document Library from Custom List

The document template is now ready to display details corresponding to each row of the document library as data gets filled in.

The last task now remains to populate the document library.

Dynamically populating the Document Library

Having already created the custom list with columns mapped to that of the document library, create a workflow for the list, to copy list data to the document library. A single action SPD SP 2010 workflow suffices, by triggering it when items are created or modified in the list.

In the given example, the document library is named Biographies, while the list is named Biography Details.

In the list workflow, add an action to create item in the document library.

How to dynamically create and populate Word Document in a Document Library from Custom List

Click on the document library name to set each field from the corresponding field in the list for all the relevant columns.

How to dynamically create and populate Word Document in a Document Library from Custom List

Having done this, the final mapping will appear as in the below image.

How to dynamically create and populate Word Document in a Document Library from Custom List

While all other fields can be edited or removed as desired, the only catch in the mapping process is to set the Path and name (*) field that is a non-removable field. This field essentially points to the file path, and it is required that this be set as illustrated below.

N.B.: Here Member Name is nothing but the Title column (primary column) of the document library or the list.

The workflow is now ready to be saved and published.

As details begin being entered or modified in the list, the workflow will make corresponding changes in the data of the document library and create corresponding documents.

24 comments

  1. why use a SPD 2010?
    I tried to do the same with SPD 2013, but without success. The word document created in the library is empty.
    Trying to create a 2010 workflow , it doesn’t complete giving an error of permission on the list

    Can you help me?

    Best Regards

    1. There’s no specific reason for using a SPD 2010 – you could use SPD 2013 also. Which SP platform are you on that gives a permission issue? I assume you have permissions on the site for contribute actions on the list and the document library and also to create the workflow.

    2. If you are using the SPD 2013 – don’t expect to see anything in the document!

      However, if you still want it to work via an SPD 2013 workflow, you’d have to create an exclusive SPD 2010 workflow (as demonstrated) for creating the document and populating it with data and then call that workflow from the SPD 2013 workflow.

  2. Very clear explanation about How to dynamically create and populate Word Document in a Document Library from Custom List in SharePoint…keep posting updated topics

  3. Hi, thank you for your explanation. In my site, all works well, but the word document is blank in the Document Library. All columns display right information in the document library. Do I miss something ?

    1. If you are using the SPD 2013 – don’t expect to see anything in the document!

      However, if you still want it to work via an SPD 2013 workflow, you’d have to create an exclusive SPD 2010 workflow (as demonstrated) for creating the document and populating it with data and then call that workflow from the SPD 2013 workflow.

      If this is not that has caused you the issue, please detail your issue.

  4. Great article – followed instructions…. list works, doc lib works, workflow works, but opening the word doc, I get the following error:
    “We’re sorry. We can’t open [document name] because we found a problem with its contents.”
    Expanding details says:
    “No error detail available”

    Any thoughts??? Will the doc have issues if any values in the doc lib are empty? Thanks!!

    1. No, the documents should not have issues even if its content is empty. If you’ve implemented in an SPD 2010 workflow with the said column limitations, I’m not expecting any errors.

      However, would you send the column details and contents that you tried to use?

  5. Hello,

    This helped me very much, I want to know if it is possible.
    When I copy the word in other library, data is not in there. Do you have some solution for that?

    Thank you!

  6. Hello, I need to populate a word template with the all items from a sharepoint 2013 list, not only with one item from the list, that I can do.
    Does any buddy knows how can I do it?
    Thanks!

  7. Is naming the columns the same absolutely necessary? I’m having random issues with this technique. Sometimes it works, other times it does not. The only “pattern” I’m noticing is the overall amount of data being placed in the list. I have, roughly, 30 multiple line text columns. When I place a line or two of text in each of them, there is no problem. However, if I place a couple of big paragraphs in a couple of the columns, the Document’s columns are all empty. Any ideas on how to troubleshoot? I’m not to familiar with debugging workflows. Any help is greatly appreciated it.

    1. I should note: the List’s columns can hold the big paragraphs, its the Document Library’s columns that are blank (empty).

  8. You don’t need to have identical column names – the mapping is done in the workflow. Hence you may choose to name a column ‘ABC’ and map it to a column ‘DEF’ with the same field type.

    For the second part of your question – yes, the lists and libraries use the multi-line columns differently. Selecting a number for multiple lines is just indicative of how many lines the text will span and has NOTHING to do with the character limit. I don’t have an exact count of characters, but I suggest you should try with incrementing characters above 256 and check the upper limit.

    Hope this helps!

  9. Hello, I was able to create the workflow and populate my library but when I select the overwrite option and make an update the updates do not show up in the library instead I receive a blank document. Any suggestions/ideas on how I can get that updated?

  10. @Supriya Tenany:
    I can’t thank you enough for that SPD 2010 tip! I spent hours upon hours creating and recreating so many lists and libraries, and then I would apply SPD 2013 workflows to test it and every time Word crashed and produced blank documents when I tried to open them. I was losing my mind and doubting my ability to use SP at all because I was sure I had done everything right, and the very second that I switched to SPD2010 I got the exact documents with all information populated that I was expecting. So very relieved!

  11. To Jordan’s error I had the same problem. Try changing the file extension to just .doc. The error went away.

    However I’m having the same issues as other with the fields in the library being populated but the document itself being blank. I’m using SharePoint 2010 Designer, so there shouldn’t be a compatibility issue. There were no steps to fix this. Is there an update?

    Thanks.

  12. The limitation I have noticed with this great solution, and maybe the reason your documents come back blank, is that there’s a 255 char max length rule imposed by Word to the Document Properties. I have seen no issues as long as the fields are below this limit, otherwise workflow errors out, and document fields turn out blank.

    Anyone has any workarounds, or solutions to this issue?

Leave a comment

Your email address will not be published. Required fields are marked *

Dublin Chamber of Commerce
Microsoft Partner
Microsoft Partner
Microsoft Partner
Microsoft Partner
Microsoft Partner
Microsoft Partner
Microsoft Fast Track
Microsoft Partner
Microsoft Fabric
MISA
MISA
Unravel The Complex
Stay Connected

Subscribe and receive the latest insights

Netwoven Inc. - Microsoft Solutions Partner

Get involved by tagging Netwoven experiences using our official hashtag #UnravelTheComplex