Skip to main content

Automatically create Word documents which include list fields

Creating Word documents containing List fields

http://blogs.technet.com/b/brenclarke/archive/2009/04/15/automatically-create-word-documents-which-include-list-fields.aspx

The example has the following components:
·         A document library which has a Word document associated which is used as the basis for all new documents
·         A list containing the fields that we want to pass into a new document
·         A workflow which creates a new Word document and copies the fields from the list into the document

Creating the document library


A document library is really just a special type of list.  There are some differences in functionality but many of the features remain the same.
First we need to create a new document library, in your browser:
·         (Top right) Site Actions > Create
·         Select “Document Library”
·         Name:  Certificates
·         Ensure the “Document template” is set to “Word document”
Next we want to add some columns to our document library for our variables to be added to

1.       Click on the “Settings” button in the list view
2.       Click on “Document library settings”
3.       Click on “Create Column
Add the following columns:
Name
Type
YourName
Single line of text
Score
Number

By default, the Title column has already been created in the list so we will use that to store our Exam title field.  There are some other columns in that are created for a document library that we will not need to use.

Creating a Word document to use as a template


Next we want to create our word document which will act as a template for all newly created documents in this library.  I am a little reticent to use the word template as we will actually just create a normal document (DOT / DOTX) rather than a Word template (DOT / DOTX).
In the settings screen of the document library:
1.       Click “Advanced Settings”
2.       Click “(Edit Template”)
Word will open the file template.dot which is located in the forms library of your document library.
3.        Save the file as a “Word document” (click okay if you are asked to confirm)
This saves the template document from Word 97-2003 format (compatibility mode) to Word 2007 format which is a DOTX file.  This allows use the document property field.  Note we are also saving the file as DOCX and not DOTX (which is a word template file and will not work).
We need to associate our document library with the new file, to do this:
1.       Document library > List settings > Advanced settings
2.       Change the template name to “template.docx”
3.       OK
Now we are ready to create the template for our certificate, go back into the Document Library > List Settings > Advanced settings and click on the Edit Template link.
You can create a nice looking document leaving space for where our list fields will go.  When you are ready to insert our fields, do the following:
1.       From the main menu select “Insert”
2.       Click “Quick Parts” > “Document Properties”
3.       You will see a list of the document properties including the columns we added (Score and YourName)
ou can select each of our fields and place them in our document – YourName, Score and Title are the three fields we will insert.
4.        Insert each of the fields into your document, they will display like this:

Here is an example of the basic layout:
And here is something a little fancier.

That completes the creation of the document library and the associated word document.

Creating a list to store our fields


We need to create a list to store our values that will be inserted into the document template.
As you can imagine, this is very straightforward:
·         Site Actions > Create
·         Custom List
·         Name:  Documents
·         Click Create
Then add our two fields into (Title will already exist)
Add the following fields to the Documents list Add the following columns:
Name
Type
YourName
Single line of text
Score
Number

You will notice this is exactly the same as what we did for the document library fields.  Our final step is to create a workflow that copies the fields from the Documents list into a new document in the Certificates document library.

Writing our workflow to create new documents in the certificates library


We are going to create a simple workflow that does the following
·         When a new item is added to the Documents list create a new Item in the Certificates library
·         Copy the title, YourName and Score fields from the Documents item into the Certificates item
This will in effect create a new document in the Certificates library that has the fields automatically populated with the values from our Documents list.  Here is how:
1.        Open SharePoint designer and connect to your site
2.       File | New | Workflow

 

  • Give the name as “Make a new certificate”
  • Attach “Documents” list to this workflow.
  • Select “Automatically start this workflow when a new item is created”
We are saying here, each time a new item is added to the Documents list then run the workflow.

3.       Click “Next”
4.       Click “Actions” > “Create List Item”


5.       Click on the “this list” link
6.       On the list selector choose “Certificates”
7.       Click on the “Name (for use in forms) ...” entry and click “Modify”
8.       In the value box, click the “Fx” button


9.        Keep the source as “Current Item” and change the field to “YourName”
10.   Click OK, OK

The above steps mean that when a item is added to the list Document  then a new document will be created in the Certificates document library and the name of the item will be set to YourName feild.
If more than one item is created with the same name then a unique identifier will be automatically added to the title.
Next we need to add our three fields to the Create List Item action.  To do this:
1.        Click the “Add” button
2.       Set this field:  Score
3.       To this value:  Click the “Fx” button
4.       Source:  Current Item
5.       Field:  YourName
Do the same for the Title and YourName values.  Your completed List Item dialogue should look like this:

You can now click “OK” and you will see SharePoint designer create the new Workflow and assign it to your list.
We are now all ready to test our new solution!

Putting it all together – testing our solution


Go back to our website and select the “Documents” list and click “New” and complete the fields and click “OK”

Back in the list of items in the Documents list you will notice a new column “Make a new Certificate” has appeared.  This column shows the status of the workflow that we created. 

Currently it will be showing “In Progress” whilst the workflow kicks and begins to run (creating the new word document in the Certificates library).  Wait for a few seconds and then refresh the page (F5).  You should see the status has changed to “Completed”

Finally, switch to the Certificates document library.  You will see our new document has been created.  When you open the document you will see that values that we passed are now contained in the Word document.



Comments

Popular posts from this blog

Sharepoint Interview questions

What is Microsoft Windows SharePoint Services? How is it related to Microsoft Office SharePoint Server 2007? Windows SharePoint Services is the solution that enables you to create Web sites for information sharing and document collaboration. Windows SharePoint Services -- a key piece of the information worker infrastructure delivered in Microsoft Windows Server 2003 -- provides additional functionality to the Microsoft Office system and other desktop applications, and it serves as a platform for application development. Office SharePoint Server 2007 builds on top of Windows SharePoint Services 3.0 to provide additional capabilities including collaboration, portal, search, enterprise content management, business process and forms, and business intelligence. What is Microsoft SharePoint Portal Server? SharePoint Portal Server is a portal server that connects people, teams, and knowledge across business processes. SharePoint Portal Server integrates information from various systems into o

SharePoint 2010 Branding: Change site actions and welcome menu arrows

Here's how you can do it. Hide the image and give our custom image element a background image. Look Like: .ms-viewselector-arrow {     background: transparent url('/PublishingImages/images/Arrow.png') no-repeat scroll 0 0;     height: 4px; /* height of the image */     width: 5px; /* width of the image */ } .ms-viewselector-arrow img {     display: none; }

Lookup field does not showing values in sharepoint2013

SharePoint Custom Form Shows HTML as Text on Lookup Fields   When creating a custom display form on SharePoint Designer, the form displays the actual HTML instead of rendering the HTML on the lookup columns. For example, see the below image: For the lookup value issue, you need to slightly modify the XSLT of the particular field from designer and add the attribute disable-output-escaping="yes" to the field.