Skip to main content
A document template is a blueprint consisting of regular text and template variables. It’s pre-made for a specific task and covers both content and design. Example signature snippet in a Microsoft Word document:
For the end-user, these templates behave similarly to the service reply template. However, how you work with them in CRMScript is different.
Template-based documents are only as good as the quality of your CRM data. It’s vital that all customer details are kept up to date. A template won’t fix bad input.
The DocTmpl database table represents an MDO list. The corresponding CRMScript carrier classes are NSDocumentTemplateand NSDocumentTemplateEntity.

Why you as a developer should embrace templates

Save time

When using templates, you won’t have to add all the customer details manually to the physical documents. CreateNewPhysicalDocumentFromTemplate() is your friend!

Prevent errors

With templates, you’re less likely to get it wrong. And consequently, you have to spend less time hunting down and correcting mistakes. You’re also less likely to have to deal with wonky documents originating from the UI.

Ensure consistency and sustainable CRMScripts

Brand-wise, you don’t have to concern yourself with marketing style guides, because they’re built into the templates.

Find templates

List all document templates with SearchEngine

SuperOffice includes some standard templates. You can find them as well as custom templates with SearchEngine.

Fetch all templates with the list agent

Fetch template info with the MDO agent

Set template for document entity

Filter documents by template

Like many MDO lists, templates can be grouped by headings, which get their labels from the Heading table. Thus the methods ending in ByTemplateHeading() target a group of templates whereas methods ending in ByTemplateType() target a single template.

NSDocument[] GetDocumentsByTemplateHeading(Integer templateHeadingId)

Fetches all documents under this heading.

NSDocument[] GetContactDocumentsByTemplateHeading(Integer contactId, DateTime start, DateTime end, Integer count, Integer templateHeadingId)

Fetches a limited number of documents within a time range for the given contact - filtered by template heading.

NSDocument[] GetContactDocumentsByTemplateType(Integer contactId, DateTime startTime, DateTime endTime, Integer count, Integer documentTemplateId)

Fetches a limited number of documents within a time range for the given contact - filtered by template ID.
To retrieve for a person rather than a contact, use GetPersonDocumentsByTemplateHeading() or GetPersonDocumentsByTemplateType().

Template variables

A template variable is a named placeholder that you can put in a document- or email template. When the template is applied, the variable is substituted with the actual value. For example, {name} translates to a company’s name while {atln} is the last name of an associate. This lets you automate the personalization of content. List of variables
The date and time in template variables are controlled by the PC’s system clock.
The short and long date formats are determined by your computer’s settings.

Substitute template variables

You can still benefit from variable substitution even if you don’t use a pre-defined template. SubstituteTemplateVariables() will parse a source string and return it with templates substituted. The encoding stays the same (binary data will be returned in Base64). The variables must have delimiters corresponding to the standard for the given generator encoding.
Non-text source data, such as the binary content of a Microsoft Word or Excel file, should be passed as Base64.
Parameters, in order:
Use an empty cultureName string to accept whatever current culture is set on the server. However, in multi-national organizations with a single server, set an appropriate value to avoid surprises.

Reference

Template types

Types 1, 5, and 6 are not used for document templates.

Frequently used fields

name refers to the label displayed in the GUI and not the physical filename of the template.
For a complete list of fields, see the database reference.

Common encoding

See the full list of encodings.