Using external tables in templates
External data is retrieved by using Select statements in a template. This section describes how to construct a statement using the Select operator and provides some common use cases.
Select operator
The select operator is used to return text values from the named return column of the external table.
This function uses the following general form:
Select
return_column
From
source_table
Where
Boolean_expression
is the name of the iSheet column. To return multiple columns, separate them with a comma.
is the external table name as defined in the External table configuration settings.
is an optional filter applied to the iSheet rows.
For example, to return all client names that are in the ClientName column from the External table called Clients, use the following statement:
select
ClientName
from
Clients
To return only names of clients located in USA, add the Where expression:
select
ClientName
from
Clients
where
'Head Office Country' is "USA"
Remember to use single quotes for table, column and row names that contain spaces, and double quotes for the values.
The row filtering expressions can be built with
Is
,
IsNot
,
IsLessThan
,
IsMoreThan
,
IsAtLeast
,
IsAtMost
operators. Such expressions can be combined using Boolean operators
and
,
or
,
not
.
All values will be returned as a list of text strings. To use them as different data types, convert them using ToInteger, ToNumber or ToDate functions.
Hyperlink columns
The hyperlink columns in iSheets contain two values: display name and URL. Prior to version 10.3, hyperlink columns returned the URL details only. From version 10.3 onwards both values are combined as an HTML anchor element which can be inserted into a Contract Express template using the "Include HTML" statement.
For example, the following statement:
select
URLcolumn
from
iSheetTable
where
ID is CustomerID
returns raw data with the html tags:
<a href="https://www.google.com/">Google</a>
Include HTML
First
(
select URLcolumn from iSheetTable where ID is CustomerID
)
returns formatted text:
Google'Include HTML' can be applied to a single text string and cannot be used on a list of text strings. Since select statements return a list of values, additional logic is needed to ensure that only one value is passed into this field.
One of the ways to do it is by applying the function First to specify that the first value found in the external table should be used. To apply it to all found values, you can use the ForEach function.
The template document must contain hyperlink style for the hyperlink to be formatted correctly. To ensure that the template document has the hyperlink style defined, enter any hyperlink to it and check that after adding a space the hyperlink is automatically formatted. This action will add the hyperlink style to the style library.
To extract only the display name or URL information, use the functions AnchorText and AnchorURL.
For example, the following statement:
AnchorText(First(select URL from iSheettest where 'text input' is "Test1"))
returns only the description:
Google
AnchorUrl(First(select URL from iSheettest where 'text input' is "Test1"))
returns only the URL:
https://www.google.com/
Columns using reserved word as name
Contract Express has reserved a list of words for special use in markup expressions. These words are expected to be used as an operator or function defined in Contract Express. Any select statements which list a reserved word as a column to be retrieved will result in a syntax error.
To bypass this issue, from 10.3 onwards it is possible to escape the reserved word by adding the underscore symbol "_" as the prefix. For example, to retrieve data from iSheet column List, add it to the Select statement as _List.