Appendix: Writing Dynamic Documents for KnowledgeKube
Before you can create a Dynamic Document Item, you will need to prepare a suitable .doc or .docx file using a word processor such as Microsoft Word. This source file should contain a mixture of static (regular text) and dynamic content, as dictated by the document's purpose.
Although you could create a dynamic document item that consists solely of static text, it would be better to use a Static Document Item for this purpose, as described in Creating a Static Document Item.
The dynamic contents of this type of document item are generated using special markers known as Fields. By inserting these fields into your source document, you can instruct KnowledgeKube to fetch values from the host model, perform calculations, conditionally hide sections of the document, and more, before generating a PDF tailored to the specific needs of an end user.
Fields are written by placing a pair of tildes (~) either side of some text, as shown in the example below:
~~CustomerDOB~~
The text inside these tildes determines the field's type, which in turn determines what will appear in place of the field when the output PDF is dynamically generated. The following table lists all valid field codes available for use in dynamic documents:
Field Type | Example | Description | Further Reading |
---|---|---|---|
Keyword | ~~CustomerDOB~~ | Displays the value associated with the keyword written inside the field. This keyword must refer to a valid question or identifier in the host model or sub-model. | |
Function | ~~GetDate()~~ | Executes a specific function and displays its result. This field can only contain a single function call, and as such it cannot be used to perform calculations or assignment expressions. | Functions |
Multiline Keyword | ~~ml(MultilineValue)~~ | Displays a value associated with the keyword written inside the field with as any carriage returns and line feeds retained. This is intended to be used to display response values from Memo questions. | |
Format String | ~~f({0:C})TotalPrice~~ | Prefacing the contents of an existing field with a format string statement will cause those contents (The TotalPrice keyword in the example shown) to have the specified format string ({0:C} in the example) applied to them. | Refer to the online MSDN article titled "Formatting Numeric Results Table". |
Line Break | ~~$nl~~ | Inserts a line break. | |
Page Break | ~~$np~~ | Inserts a page break. | |
Total Page Number | ~~$tp~~ | Displays the total number of pages in the generated document. | |
Embed Current Page Number | ~~$p~~ | Displays the number of the current page. | |
Image | ~~Image(ImageName, ImageType, ImageOptions, ImageWidth, ImageHeight, ImageData)~~ | Displays a specific image. The image source can be a website URL, a base64 string, or the name of a KnowledgeKubeImage Item. | Dynamic Document Images |
Begin Inclusion | ~~include(CustomerStatus = "Approved")~~ |
This type of field must be paired with a subsequent endinclude field. If the expression in the include field's parentheses returns True, all content between the include and its paired endinclude will be displayed in the resulting PDF. Otherwise, that content will be hidden. If the expression references a question keyword, that question must be added to the Expression Parser for the function to work. |
|
End Inclusion Closer | ~~endinclude~~ | This type of field must be paired with a preceding include field. It marks the end of the content that will be excluded unless the paired field's expression returns True. | |
Not Empty Check | ~~!Empty(MiddleName)~~ |
Wrapping the contents of a Keyword Field (The MiddleName keyword in the example shown) inside a Not Empty Check will cause the result to be hidden if the value associated with the specified keyword is an empty string. This can be used, among other things, to hide fields that reference optional questions that have not been given a response. If the field is hidden, the entire paragraph that contains the field will be hidden, causing subsequent paragraphs to move up into its place. If the keyword has a value of 0, or it refers to a variable with no Initial Value, the document will display the literal value of "0". |
|
Embed Dynamic Document |
~~inserttemplate(DocumentKeyword)~~ or ~~inserttemplate(DocumentKeyword1, DocumentKeyword2, ...etc)~~ |
Embeds the contents of one or more dynamic documents inside the current one, at the position of the inserttemplate field. The result is known as a Document Pack. This field can be used as often as needed inside a single document. |
Embedding One or More Dynamic Documents Inside Another |
Data Source Embed | ~~ForEachDataSourceRow(DatasourceName, FilterName, DocumentKeyword, IsGrid, HasHeader, VariableParameters, Refresh)~~ | Fetches a set of filtered data from a data source, which is then collated inside a separate document (Identified by the DocumentKeyword parameter in the example shown). The contents of the second document are then embedded inside your main document at the position of the ForEachDataSourceRow field. | Appendix: Embedding Queried Data in a Dynamic Document |
If a document-specific function has any optional parameters that you do not need to change, write nothing between the commas where each optional parameters' argument should be. If you do not need to add any further arguments after those you have already left blank, you can exclude the optional parameters altogether. For example, you could write ~~MyFunction(Arg1,Arg2,,,,Arg6)~~, and if Arg6 was no longer required you could re-write the function as ~~MyFunction(Arg1,Arg2)~~.