Merge in External Data: XML Strings

To merge external data (in the form of an XML string) into an S-Docs document, you can create an S-Docs Job record and write the external data to the S-Docs Job record. You can then reference the XML data values as merge fields in your template.

For example, if you have {{!MyXXXField}} in your template and you set write <MyXXXField>Tutorial</MyXXXField> to the S-Docs Job, you will see "Tutorial" in your generated document.

Nested XML Tags

This feature also supported nested XML tags, with the * character used as a delimiter between each level:

Apex Code

You can also use this feature in your Apex code (for example, in an Apex class that does a webservice callout to retrieve the XML data string). In your Apex code, you can use the function SDBatch.writeRecordDataXML(SDJob__c sdjob, String xml) to write the XML string to an S-Docs Job record (this will store the XML string in the S-Docs Job's SDOC__RecordDataXML__c field, as well as the SDOC__RecordData2XML__c field if the string is too large to fit in the first field alone). For example:

Given that you've configured your template to use merge fields referencing the XML data values, this code should generate a document that has your XML data merged into the specified locations.

Merge in External Table Data

You can also merge in external table data into your S-Docs documents. This involves formatting your external table data into an XML string and using Apex code to pass that string into an S-Docs Job record. This will allow the external table data to populate a table within an S-Docs document. Let's take a look at an example to see how this works.

First, we built out a table within the S-Docs template editor that includes three columns -- one for product name, product description, and product code -- information that we'll assume is currently stored outside of Salesforce. Here's the source code for our table:

As you can see, we've included some styling CSS within the <style> tags, and then defined our three table columns within <th> tags. Next, we added a LineItems statement within the <tbody> tags -- this statement will use your XML string to populate the table. Note that the <listname> tags include the externalList="true" attribute to denote that we will be merging in external data.

To ensure that our external table data will merge in correctly, we first need to format it into an XML string. You can write Apex code to format your table data into XML that follows the format below. Each product record includes one XML tag for each table column (in our example, 3 per record), and is enclosed within parent tags that have the same name as the <listname> in our S-Docs template.

Once your external table data is formatted correctly, the last step is to write Apex code similar to the following so that your XML string can be written to an S-Docs Job record and merged into your S-Docs template.

This code will generate a document with your XML data merged into the table. Using the data listed above, the generated document will look like this: