Articles in this section

How to get the value from a specific column and row within a Data Source using DataSources[]

This article explains what the DataSources[] function is and provide examples of how it can be used with the binding syntax in smart templates.

  Prerequisites

  • Library and at least one Dynamics module enabled.
  • Templafy Desktop and Office VSTO add-in installed.
  • Space owner access to the Templafy tenant.

What is the DataSources[] function? 

DataSources[] is a function that returns the values from a specific data source row.

DataSources[] logic

Syntax {{DataSources.DataSourceName[NameValueToLookUp].DataSourceColumnName}}

  Note

The DataSources[] function is used for (local) data sources while the ExternalDataSources[] function is used to capture data from an external data source row.

DataSources[] function examples

In the examples below these data sources are used. The column Country of the Offices data source is a reference to the column Name of the Countries data source:

datasources_reference.png

  Important

Please note that creating data sources requires owner or admin rights to the tenant.

Example 1

Using the DataSources[] function with plain text to retrieve the postal code of the Eindhoven office.

Binding {{DataSources.Offices["Office Eindhoven"].PostalCode}}
Input n/a
Output 5611 ZB

  Important

  • Plain text must be enclosed in quotation marks.
  • The DataSources[] function is case sensitive, so for example the binding {{DataSources.Offices["Office Eindhoven"].Postalcode}} will not work.
  • The binding {{DataSources.Offices["Office eindhoven"].PostalCode}} will work, but as 'Office eindhoven' does not exist ('eindhoven' is not the same as 'Eindhoven'), the output will be empty.

Example 2

Using the DataSources[] function with the "OfficeName" flexible dropdown question originating from the response form to retrieve the correct postal code for the office. 

Binding {{DataSources.Offices[Form.OfficeName].PostalCode}}
Input Office Copenhagen Office Eindhoven
Output 1403 5611 ZB

Example 3

Using the DataSources[] function with the "OfficeName.Name" dropdown question originating from the response form to retrieve the correct postal code for the office.

Binding {{DataSources.Offices[Form.OfficeName.Name].PostalCode}}
Input Office New York Office Copenhagen
Output 10007 1403

  Important

Please note, in the binding you need to use {{Form.OfficeName.Name}}, because it's a dropdown field.

Example 4

Using the DataSources[] function with the "OfficeName" flexible dropdown question originating from the response form to retrieve the country of the office.

Binding {{DataSources.Offices[Form.OfficeName].Country.Name}}
Input Office Berlin Office Sydney
Output Germany Australia

  Important

Please note that the Country is stored in the Name column of the Countries data source and is used as a reference in the Offices data source.

Example 5

Using the DataSources[] function with the "OfficeName" flexible dropdown question originating from the response form to retrieve multiple fields from the data source row.

Binding Location Templafy {{DataSources.Offices[Form.OfficeName].City}}: {{DataSources.Offices[Form.OfficeName].Address}}, {{DataSources.Offices[Form.OfficeName].PostalCode}}, {{DataSources.Offices[Form.OfficeName].City}}, {{DataSources.Offices[Form.OfficeName].Country.Name}}
Input Office Sydney Office Berlin
Output Location Templafy Sydney: 151 Clarence Street, NSW 2000, Sydney, Australia Location Templafy Berlin: Lützowstr. 100, 10785, Berlin, Germany

  Important

Please note, for all examples explained, if no value is resolved then "" is returned.

Example 6

Using the DataSources[] function to insert an image stored in a data source. 

Binding {{DataSources.DataSourceName["ImageName"].DataSourceColumnName}}

Example 7

If you want your email signature or Word document to contain a 'tip of the day' (showing a different tip every day) then create a data source containing all 366 possible dates (format 'month/day') and texts like this:

tipoftheday.png

Insert a tip based on today's date:

Binding {{DataSources.TipOfTheDay[FormatDateTime(Now(),"MM-dd","en-US")].Tip}}
Input Today's date = "January 2" Today's date = "December 31"
Output "To increase the font size, highlight the text and then press Ctrl+]." "To insert a non-breaking hyphen press Ctrl+Shift+_."

Insert a tip based on the value of the "Date" question originating from the response form:

Binding {{DataSources.TipOfTheDay[Form.Date,"MM-dd","en-US")].Tip}}
Input Date = "January 2" Date = "December 31"
Output "To increase the font size, highlight the text and then press Ctrl+]." "To insert a non-breaking hyphen press Ctrl+Shift+_."

Example 8

Using the DataSources[] function with a HostSystem binding.

This example shows how the DataSources[] function can be used to add a specific image to a document, while the external data originating from the App connector or API request only contains text.

In the example this JSON file is used:

{
"email": "john@mycompany.com",
"data": {
"Language": "en-us",
"OrderId": 12345,
"Product": "Apple"
}
}

The product can be any fruit, like 'Apple', 'Banana', 'Orange' etcetera.

The template currently only contains fields to display the Order ID and Product. Both fields are configured like this:

hostsystemorderid.png

To add a field showing an image of the selected fruit in the document, follow the steps below:

  1. In the Admin Center, create a Products data source.
  2. Add a field of Type 'Image' and the name 'Image'. The result looks like this:
    datasourceschemaimage.png
  3. In the Products data source add the value 'Apple' to the Name column and a picture of an apple to the Image column. Do the same for the other types of fruit. The result looks like this:
    datasourceproductsfruits.png

      Important

    • Values in the Name column must match the names used in the external data source.
    • Values are case sensitive.
  4. In the template position the cursor below the Product field.
  5. In Template Designer click + Add smart field.
  6. Click Custom image binding.
  7. In the Display name field enter a name, for example 'Product image'.
  8. In the Image field use the binding {{DataSources.Products[HostSystem.Product].Image}}.
  9. Optional: set the Height to '2 cm'. The result looks like this:
    datasourceshostsystemproduct.png
  10. Save the template and upload it to the Admin Center.
  11. When a user creates a document using the Templafy API, the document now also shows an image of the selected fruit:
    productfruits.gif
hostsystem header headers help text tech_role
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.