In this video, we explore how to use the Lightning Forms Document Generator to create Microsoft Word documents from a SharePoint list item. The Word document can then be printed, shared, or saved as a PDF.
Before you start using the Lightning Tools Document Generator, you first need to create a Microsoft Word document that references the column names within your SharePoint List and/or sublists. Once this has been completed, you can upload the Microsoft Word document using the Document Generator custom action.
*Note that the Document Generator is a premium action with Lightning Forms.
Creating your Document Template
- Create a new Microsoft Word Document.
- Style the document to resemble the look and feel for your organization’s requirements.
- Reference the fields on your SharePoint list form using square brackets around the field name. e.g. [[Title]]. (Remember to use the programmatic name and not the display name. e.g. ‘Approved By’ may have a programmatic name such as ‘Approved_x0020_By’ as shown below.


- Open the Expression Builder within Lightning Forms against the Display Form, Edit Form, or New Form to see a list of fields with their display names and programmatic names as shown below:


- See the Syntax section below for how to add things like images and hyperlinks.
- Save your Microsoft Word template and name it appropriately e.g. Expense_Report_Template.DOCX
Referencing Fields in a Sub List
If you use a Sub List within your SharePoint list, you can display the column names within a Loop statement allowing for each item displayed within the sub list to be displayed on the Word document. To create the Table and Loop statement:
- Create a Table with two rows, and the number of columns based on how many fields you wish to display from your sub list within your Microsoft Word document. One row will be for the header, and the second row for the field references. If you wish to display First Name, Last Name, Email, Phone from a sub list, you will need a 4 x 2 table.


- Provide column headers for each field and format your table to your requirements.
- In the first column, second row, add a Loop referencing the Sub list name and the column name you wish to display using the format: [[loop sub list name]][[Title]]. An example is provided below for a Sub List named Expense Items.


- Add the other required columns e.g. [[ClaimAmount]].
- Add the final column and close the loop using [[end loop]]
- Save your document.
Download an example Word Document
ExpenseReportPrint.docx (201 downloads)It is recommended to use the Document Generator for a saved list item. Therefore if you are using a New Form to create New Items, the first action would need to be ‘Save Form’. If you are using the Edit Form or Display Form, you don’t need to use a Save Form action before the Generate Document action.
- Edit the SharePoint form using Lightning Forms.


- Choose Actions, Command Bar to add a new action button to the top of your form.
- Click the + icon in the Command Bar Actions side panel.


- Provide a display name and set an icon for your custom command bar button.
- Click Configure Actions.


- Select ‘Generate Document‘ from the list of Action Types
- Upload your saved Word Document
- Select ‘For single item’ from the Data field.
- Select your SharePoint List (Just the main list, not the sub list)
- Set the Item ID field to [[ID]]
- Leave the default Target to Open in Browser
- Set the filename pattern for your reports. e.g. ‘ExpenseReport_[[Title]]_[[ID]]’
- Click Save


You can now test your Command bar action by opening or editing an item within your list.
If you use Lightning List Actions, you can also create Command Bar buttons within a SharePoint List View.
- Click Lightning List Actions within your SharePoint List.


- Choose a name, icon, and set the action visibility to ‘Selected Items’.
- Configure the list action using the steps 6-11 from above.
- The Action button will display when you select multiple list items within your view.
Document Generator Word document syntax
Template expressions | Any kind of string Template Expression | [[Title]] [[Firstname]] |
Assignment Expressions | Start with “[[=” and any kind of string Expression | [[= [[Title]] + “, ” + [[Firstname]] ]] |
Function Code Expressions | Start with “[[{” in the Tag property. Write your complex expression as content in the placeholder | [[{ var arr = [[@Loop(‘Invoice’, [[{ return [[Total]]; }]] )]]; var sum = 0; arr.forEach(n=>sum +=n); return sum; }]] |
Lookup Values | Use the [[Lookup.FieldInternalName]] notation to get any value from the target list of a lookup | [[Department.Code]] [[Department.Author]] [[Department.Key]] -> to get the item ID of the department |
If Conditions | Start with [[if …]] and any kind of boolean Expression (Condition). Ends with [[end if]] Everything between the starting and the ending tag will be visible if the condition is true. This can be text, an image etc. | [[if [[Budget]] > [[Outgoings]] ]] [[Title]] [[end if]] [[if {return ([[Budget]] > [[Outgoings]]);} ]] [[Title]] [[end if]] [[if [[Status]]!=”Completed” ]] [[Title]] [[end if]] |
Loops | Start with [[loop]] for looping over multiple items of selected list. If CAML Query is configured for this action link, looping will be filtered according to it. Start with [[loop SublistTitle]] for looping over the sublist items filtered by lookup to the parent list. Use filterlookupfield(‘field_internal_name’) param to specify which lookup field to use for sublist in a case when several lookups on the same list exist. It’s optional where there is just one lookup field. Also RowLimit is hardcoded for 200 items for query, but needed number can be specified with optional rowlimit(number) param. If list that is not a sublist is selected (doesn’t have lookup to the list selected in action link configuration), no filtering will be applied. Iteration ends with [[end loop]] | [[loop]] [[Title]] [[end loop]] [[loop SubListTitle filterlookupfield(‘field_internal_name’) rowlimit(number)]] [[Title]] [[Firstname]] [[end loop]] |
Filtered Loops | Where ‘SomeView’ is a view .aspx page title, such as AllItems. The order and filter of the view are applied. If CAML query is added (optional), it is united with view query using an ‘and’ operator. | [[loop SublistTitle view(‘SomeView’) query(‘<Where><BeginsWith><FieldRef Name=”Title” /><Value Type=”Text”>[[{return [[Title]];}]]</Value></BeginsWith></Where>’)]] [[Title]] [[end loop]] |
Loops over documents in sublibraries | Use the Scope=”Recursive” property on the query to get documents in a folder, when used as sublibrary of a form. Combine recursive scope and filter in CAML query to filter the listed document’s metadata. | [[loop SublibraryName query(‘<View Scope=”Recursive”></View>’)]] [[FileLeafRef]] [[Title]] [[OtherField]] [[end loop]] [[loop SublibraryName query(‘<View Scope=”Recursive”><Query><Where><Eq><FieldRef Name=”IsActive” /><Value Type=”Boolean”>1</Value></Eq></Where><OrderBy></OrderBy></Query></View>’)]] [[FileLeafRef]] [[Title]] [[OtherField]] [[end loop]] |
Nested Loops | Looping over sublist inside of the loop over multiple items of parent list is supported. Looping over several sublists, or sublist of sublist are supported as well. | [[loop]] [[Title]] [[loop SubList1]] [[Title]] [[Firstname]] [[end loop]] [[loop SubList2]] [[Title]] [[Firstname]] [[end loop]] [[end loop]] [[loop]] [[Title]] [[loop SubList]] [[Title]] [[Firstname]] [[loop SublistOfSublist]] [[Title]] [[end loop]] [[end loop]] [[end loop]] |
Loops over table rows | It is possible to loop over table rows by adding the loop inside the table. In case of nested loops, if loop on parent list is placed into the external table, this will render separate table for each parent item | [[loop SubListTitle]] [[Title]] [[Firstname]] [[Lastname]] [[end loop]] [[loop]] [[Title]] [[Title]] [[Firstname]] [[Lastname]] [[end loop]] [[end loop]] |
Image | Show an image inside the document. You can optionally specify the static width and height of the image and also max/min width and height. Width/height parameters are not mandatory, can be ” (empty string) or null. | [[image ([[Picture]], width, height, maxwidth, maxheight, minwidth, minheight)]] Without width and height: [[image ([[Picture]])]] Static width and height: [[image ([[Picture]], 50, 50)]] Static width: [[image ([[Picture]], 20)]] Static height: [[image ([[Picture]],,150)]] [[image ([[Picture]], ”, ”, 100, 300)]] [[image ([[Picture]], maxwidth=100, maxheight=300)]] [[image (url=[[Picture]], maxwidth=100, maxheight=300)]] |
Link | Create a link in the document | [[link ([[Hyperlink]])]] [[link ([[Hyperlink.Url]], [[Hyperlink.Description]])]] [[link (url=[[Hyperlink.Url]], text=’linktext’)]] |