Populating Merged Documents with External Data
Before the hosting application can populate merged documents with external data, mail merge fields must be inserted into the merged document and mapped to the external data. How external data is mapped to given mail merge fields is determined by the WordprocessingML element <fieldMapData>
.
Consider the example merged document from the previous example which contained the two mail merge fields calling for Courtesy Title
and Last Name
. The WordprocessingML below demonstrates how mapping of the external data to the merged document's mail merge fields occurs:
<w:fieldMapData> <w:type w:val="dbColumn" /> <w:name w:val="Customer Title" /> <w:mappedName w:val="Courtesy Title" /> <w:column w:val="9" /> </w:fieldMapData> <w:fieldMapData> <w:type w:val="dbColumn" /> <w:name w:val="Customer Last Name" /> <w:mappedName w:val="Last Name" /> <w:column w:val="10" /> </w:fieldMapData>
Within the first <fieldMapData>
element, the child elements <column>
, <name>
, <type>
, and< mappedName>
specify that the data contained within tenth column titled 'Customer Title', in the specified external database, is to be mapped to the mail merge field calling for 'Courtesy Title' data, respectively. Within the second <fieldMapData>
element, the child elements <column, name>
, <type>
, and< mappedName>
specify that the data contained within eleventh column in the specified external database is to be mapped to the merge field titled Customer Last Name
or the predefined merge field name Last Name
.
Once a merged document's mail merge fields have been mapped to external data, the hosting application and/or data source access application may populate the respective fields with applicable external data.
Consider a conforming hosting application and/or data source access application that wishes to populate the mail merge fields within the merged document from the previous example with applicable external data. In addition, consider that the specified external data source contains two records--one for Mr. John Doe and one for Ms. Jane Smith. With external data from the Customer Title
column mapped to the Mail Merge field calling for Courtesy Title
data, and the Customer Last Name
column mapped to the Mail Merge field calling for Last Name
data to populate the fields within this merged document with external data.
The mail merge process will then run through the specified external database and populate the mail merge fields with the data from the Customer Title
and Customer Last Name
columns in the specified database, and generate two of merged documents containing the specified external data as well as the static contents of the source document (illustrated in the table below):
Source Document |
Merged document populated with first external data source entry |
Merged document populated with second external data source entry |
---|---|---|
Dear{MERGEFIELD "Courtesy Title" \m} {MERGEFIELD "Last Name" \m}, Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sincerely, |
Dear Mr. Doe: Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sincerely, |
Dear Ms. Smith: Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sample text. Sincerely, |