Articles in this section

How to find the data available from the SharePoint App Connector

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:

  1. In SharePoint go to the page where the Create Document button is shown:
    SharePointAppConnector_CreateDocument.png
  2. Click Create Document. The Composer opens.
  3. Press F12 to open the Developer Tools of the (Composer) browser and select the Network tab.
  4. In the Composer select any template and click Next.
  5. In the lower right corner click Other actions.
  6. Now in the 'Name' task pane on the Network tab in the Developer Tools click create.
  7. In the right task pane select the Headers tab and scroll down to the section named 'Request Payload'.
  8. Expand externalContent.
  9. Expand List,Site andWeb. The result looks like this:
    2_sharepoint_developertools.png
  10. 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'.

  Important

Field 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:

  1. Download the Templafy template to your local folder.
  2. Go to a SharePoint site and upload the template from your local folder.
  3. Open the template now stored in SharePoint, and add the Document ID content control to the template.
  4. Changes to the template are saved automatically.
  5. Download the updated template from SharePoint and save it to your local folder.
  6. In Templafy admin, select the template you downloaded in the first step.
  7. Choose Replace, and select the template with the Document ID from your local folder.
  8. 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.

  Note

The 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:

  1. Download the template that already has the Document ID and custom XML metadata. For example: Letter.docx.
  2. Change the .docx extension 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.
  3. 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
  4. 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. 
  5. Search for  _dlc_DocId . You should find a  w:dataBinding element similar to:
  6. 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.

  7. Do not change storeItemID. Leave this value unchanged. Also leave w:prefixMappings unchanged. This is important because the content control should continue using the existing Custom XML data store.
  8. Open word/header1.xml, or another header.xml file when the Document ID is used in headers. Repeat the steps.
  9. Save the XML file(s). Make sure your editor does not change the files into `.txt` files. Also avoid changing the XML encoding.
  10. Re-create the ZIP package. This step is important. Go inside the extracted folder and select its contents:

    _rels
        customXml
        docProps
        word
        [Content_Types].xml

    Zip these items. Do not zip the parent folder itself.

  11. Rename .zip back to .docx. Rename Letter.zip to Letter.docx.
  12. 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.
  13. Replace the template in Templafy Library.
  14. 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.
  15. Test exactly the same template in Site B.

 

quick parts repeater create template multi-level filtering a malformed uri was found in the document tech_role
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.