This article explains how to find the data accessible from SharePoint when using the SharePoint App Connector so it can be used in smart templates through the binding syntax.
Prerequisites
|
How to find available data from the SharePoint App Connector
The steps to find available data from the SharePoint App Connector, are:
- In SharePoint go to the page where the Create Document button is shown:
- Click Create Document. The Composer opens.
- Press F12 to open the Developer Tools of the (Composer) browser and select the Network tab.
- In the Composer select any template and click Next.
- In the lower right corner click Other actions.
- Now in the 'Name' task pane on the Network tab in the Developer Tools click create.
- In the right task pane select the Headers tab and scroll down to the section named 'Request Payload'.
- Expand
externalContent. - Expand
List,SiteandWeb. The result looks like this: - The (purple) fields can now be used in bindings in a template using a HostSystem binding.
For example{{HostSystem.List.Title}}will show the value ‘Documents’ in the document,{{HostSystem.Site.GeoLocation}}will show 'EUR' and{{HostSystem.Web.Title}}will show 'My Team Site'.
ImportantField names are case-sensitive. |
How to add Document ID to the template
The Document ID is assigned when the document is saved in SharePoint, provided the Document ID Service is enabled on the site. Because of this, a {{HostSystem}} binding cannot be used. Instead, use the built-in Microsoft Word document property and make sure the SharePoint metadata custom XML is included in the template.
To set up the template, follow these steps:
- Download the Templafy template to your local folder.
- Go to a SharePoint site and upload the template from your local folder.
- Open the template now stored in SharePoint, and add the Document ID content control to the template.
- Changes to the template are saved automatically.
- Download the updated template from SharePoint and save it to your local folder.
- In Templafy admin, select the template you downloaded in the first step.
- Choose Replace, and select the template with the Document ID from your local folder.
- The template is now customized and ready for use.
Repeat this process for each template that needs the SharePoint Document ID, or use this template as a base for other templates.
When a document is saved in any SharePoint site with Document ID enabled, property promotion updates the custom XML part, and the Document ID content control displays the correct Document ID for that site.
NoteThe custom XML part embedded in the template may contain old values, including a previous Document ID, until the new document is saved to SharePoint and reopened. Users might briefly see the previous Document ID. You can clear these values in the XML part while keeping the structure intact. |
When the Document ID is not updated in SharePoint sites other than the one where the template was created, additional adjustments are needed.
For example, if the template is created in Site A, Word sets up an XML mapping for the _dlc_DocId property. This mapping uses a namespace that is specific to Site A. When the document is then saved to Site B, SharePoint generates and stores the new Document ID. However, the Word content control continues to reference the namespace from Site A. As a result, the updated Document ID is present in the document metadata, but Word cannot display it in the content control.
To make the template usable across different SharePoint sites, we suggest updating the Document ID mapping so it does not depend on a site-specific namespace.
Currently, the content control uses a mapping such as:/ns0:properties[1]/documentManagement[1]/ns3:_dlc_DocId[1]
In this mapping, ns3 points to the namespace of the site where the template was first created.
We recommend changing the mapping to:
/*[local-name()='properties'][1]/*[local-name()='documentManagement'][1]/*[local-name()='_dlc_DocId'][1]This approach finds the _dlc_DocId property by its name, without depending on a specific SharePoint namespace.
With this update, the template can retrieve the Document ID from any SharePoint site. This removes the need to maintain different mappings or templates for each site.
The most reliable manual method is to update only the w:xpath value in the relevant content controls. Avoid changing the Custom XML data or the storeItemID.
Manually make the Document ID mapping site-independent by following these steps:
- Download the template that already has the Document ID and custom XML metadata. For example: Letter.docx.
- Change the
.docxextension to.zip. A Word .docx file is actually a ZIP package containing XML files. Rename: Letter.docx to Letter.zip. If Windows does not show file extensions, enable: File Explorer > View > Show > File name extensions. -
Extract the ZIP file. Extract the ZIP to a temporary folder. Inside you will see folders such as:
_rels customXml docProps word [Content_Types].xml - Open `word/document.xml`. Preferably use an XML/text editor such as Notepad++ or Visual Studio Code. Do not use Microsoft Word to edit this XML file.
- Search for
_dlc_DocId. You should find aw:dataBindingelement similar to: -
Change only the
w:xpath. Replace:/ns0:properties[1]/documentManagement[1]/ns3:_dlc_DocId[1]
with:/*[local-name()='properties'][1]/*[local-name()='documentManagement'][1]/*[local-name()='_dlc_DocId'][1]. So the result should look similar to:<w:dataBinding w:prefixMappings="..." w:xpath="/*[local-name()='properties'][1]/*[local-name()='documentManagement'][1]/*[local-name()='_dlc_DocId'][1]" w:storeItemID="..."/>Do this for all occurrences in
document.xml. - Do not change
storeItemID. Leave this value unchanged. Also leavew:prefixMappingsunchanged. This is important because the content control should continue using the existing Custom XML data store. - Open
word/header1.xml, or another header.xml file when the Document ID is used in headers. Repeat the steps. - Save the XML file(s). Make sure your editor does not change the files into `.txt` files. Also avoid changing the XML encoding.
-
Re-create the ZIP package. This step is important. Go inside the extracted folder and select its contents:
_rels customXml docProps word [Content_Types].xmlZip these items. Do not zip the parent folder itself.
- Rename
.zipback to.docx. Rename Letter.zip to Letter.docx. - Open the document in Word. Open the document locally first. Check that:
- Word opens it without a repair message.
- The formatting is unchanged.
- The Document ID content control is still present.
- Replace the template in Templafy Library.
- Test in SharePoint Site A. Create a document from the modified template in the first SharePoint site. Allow SharePoint to assign the Document ID. Confirm that the content control displays the correct Document ID.
- Test exactly the same template in Site B.
Comments
Article is closed for comments.