DocumentData is a tool used for fetching data from a database, transforming the received data, and outputting it into Word, PowerPoint, Excel or Outlook. It is a useful tool that can be used for configuring dynamic templates that needs up-to-date data inserted in the documents.
Contents
How does it work? [Back to top]
DocumentData works by executing commands in three major areas. Fetch, transform and output. These areas are illustrated below, and will be further elaborated upon in this article.
Fetching
When DocumentData fetches data, it communicates to a database with typically a query. Different clients have different types of databases and therefore require different integrations. An example of one these integrations, is SqlData
which is documented here. With this, you can query data from a database, which will then be temporarily be stored in document data.
For an in depth guide for fetching data, see this article.
Transforming
With the fetched data, DocumentData now has it temporarily stored and can assign the data to different variables, and transform the data in these variables. To do this we use the following command:
<Cmd case="SkabelonDesign.DocumentData:DefineData" variableName="XX">
.
The variable name assigned here is what you need to reference to later in the process, when you make your content controls bindings. To assign data to the variable, see the example below:
<cmd case="SkabelonDesign.DocumentData:DefineData" variableName="CaseNumber">
<Doc.Prop.CaseNumber>
<Doc.Prop.CaseNumber/>
</Doc.Prop.CaseNumber>
</cmd>
In the simple example above, there are first a visibility set with <Doc.Prop.CaseNumber>
and </Doc.Prop.CaseNumber>
. Please note how the /
is set in the code.
This acts as a container saying "if this value exists, insert the value within this container". In this case we insert the same value as we are using for visibility <Doc.Prop.CaseNumber/>
, which when expressed like this, with the /
at the end of the expression, prints the value.
If you are in doubt, if what data is being fetched and what names the data has, you can use our debug command:
<Cmd case="SkabelonDesign.DocumentData:OutputDebug"/>
This provide an overview of the data in the form of a .txt file.
You can also supplement the data saved in the variable by using <s> </s>
for adding strings within the tags and <s><![CDATA[ ]]></s>
for adding empty spaces and line breaks. See the example below for how this can be done.
<cmd case="SkabelonDesign.DocumentData:DefineData" variableName="CaseNumber">
<Doc.Prop.CaseNumber>
<s>Your case number: </s><Doc.Prop.CaseNumber/> <s><![CDATA[
]]></s> <Doc.Prop.CaseRegarding/>
</Doc.Prop.CaseNumber>
</cmd>
In the example above, we have hardcoded a supplement text to be inserted before the <Doc.Prop.CaseNumber/>
and specified that <Doc.Prop.CaseRegarding/>
should be inserted a line below.
Be aware that when using <s><![CDATA[ ]]></s>
, an indent will show in the output if you try to tab your code for code visibility.
Output
With your defined data saved in DocumentData variables, you can specify where it should be inserted in Word/PowerPoint/Outlook.
For inserting data from DocumentData in Word, we use a content control binding.
See the example below, for a typical example of a DocumentData content control binding.
{"SkabelonDesign":{"type":"Text","binding":"SagsNummer","visibility":{"action":"Show","binding":"SagsNummer","operator":"Equals","compareValues":[""]}}}
In the example above, we see a typical binding for inserting from DocumentData, but with a visibility that sets the binding to only show, if the variable from DocumentData has any data.
For an in depth explanation of how to outputting data with DocumentData, read this article.
Plugin for DocumentData [Back to top]
Ensure that you have the latest plugin for DocumentData before you start configuration. Right-click at the SDUP concerned and select the following option:
Just give me something to copy! [Back to top]
For a quick setup see the example below. Note that you might need different means of fetching, but in this example, we will use SQLData.
<cmd case="SkabelonDesign.DocumentData:EnablePendingChanges"/>
<Cmd
prefix="foo"
case="SkabelonDesign.SqlData:FetchAndInsertData"
query="SELECT * FROM [dbo].[CaseNumbers] WHERE [bar] = '{baz}'"
connection="Data Source=fool01\Advosys;Initial Catalog=Advosys;Integrated Security=SSPI"
/>
<cmd case="SkabelonDesign.DocumentData:DefineData" variableName="CaseNumber">
<foo.CaseNumber>
<foo.CaseNumber/>
</foo.CaseNumber>
</cmd>
<Cmd case="SkabelonDesign.DocumentData:OutputDebug"/>
<cmd case="SkabelonDesign.DocumentData:Commit"/>
Read this article for more information on how to do this. Note that you can delete the line with "OutputDebug" if do not want to see what data is fetched.
{"SkabelonDesign":{"type":"Text","binding":"CaseNumber","visibility":{"action":"Show","binding":"CaseNumber","operator":"Equals","compareValues":[""]}}}
Example above is the typical binding to use, the same example from earlier in this article. This should be configured in Word, like in the simple example below.
Comments
0 comments
Article is closed for comments.