Use Document Creation to generate documents from records in your app. Document Creation relies on two things:
- A template built in table settings that determines what data should be included in documents
- A formula-URL field added to reports or records that allows app users to generate documents
Learn more about the document creation process.
This article covers how to add formula-URL fields to your app that allow app users to generate documents. It also lists other methods you can use to implement Document Creation into your workflow.
In this article
Requirements
Before you can add a functioning formula that allows users to generate documents to your table, create a document template.
Add a formula-URL field to your table
Learn more about adding a formula field to your table in Adding formula fields to tables.
Copy or install the example formula
Find and install the Document Creation formula from the Exchange. In the Exchange, the formula is called Generate Document. Learn more about getting resources from the Exchange.
You can also copy the formula below and paste it into the formula-URL field you created for your table.
var number recordId = [Record ID#]; //record ID# you want you are generating the document from
var number templateId = 1; //ID of the template you'd like to generate
var text tableId = Dbid(); //tableID of the table the template was built in
var text fileName = "myqbdoc"; //name of the generated file
var text format = "pdf"; //output formats: html, pdf, docx
var text qbRealm = NotRight(NotLeft(URLRoot(), 8), "/") ; //gets the current realm, required for API requests
"https://api.quickbase.com/v1/docTemplates/" & $templateId &"/generate?&tableId=" &
$tableId & "&realm=" & $qbRealm & "&filename=" & $fileName & "&format=" & $format
&"&recordId=" & ToText($recordId)
Enter the template ID in the formula
Edit the template ID in the formula for it to function correctly.
Find the template ID
- Go to table settings > Document templates.
In sidebar navigation, select the three-dot more menu that appears on the table name on hover. This menu shows several shortcuts to table settings, and Document templates is in the list.
- Find the template ID from the template list. When you first save a template, you also have the option to copy the template ID.
Add the correct template ID to the recordId
variable
The example formula has several variables. Variables are defined at the beginning of formulas and referenced later in the formula. Learn more in Formula variables.
After you have pasted or installed the formula into the formula-URL field you created on your table, edit var number templateId = 1
so that the number after the equal sign is the correct template ID.
If you only have one template for your table, you do not need to change the template ID. This is because the ID for your template will also be 1.
Change other settings in the formula (optional)
Other document settings are also controlled in the formula:
- File name of documents after they are generated (1)
- File type that is generated (2)
You can also use the formula to override settings you've set in the template builder, including:
- Margins
- Margin units
- Orientation
- Page size
The following table lists settings and input options.
Setting | Location in formula | Input options |
Required | ||
1 – File name |
|
Replace "myqbdoc" with your desired file name File names can include alpha-numeric characters |
2 – File type |
|
pdf, html, docx |
Optional—use to override settings in the template builder | ||
Margins |
|
Numeric values, formatted from top right to bottom left and separated by spaces |
Margin units |
|
in, cm, nm, px |
Orientation |
|
portrait, landscape |
Page size | pageSize=Letter |
Letter, Legal, Tabloid, A3, A4, A5, A6 |
This is what a formula with all possible settings would look like:
Parts of the formula you should not change
To keep the formula working correctly, do not change:
-
var number recordId = [Record ID#]
- Record ID# is a field automatically created for every table. This variable references that field so that Quickbase knows what record to apply the template to.
- If you have changed the name of this field in your table, update the formula so it matches the updated name.
-
var text tableId = Dbid()
- References the table the field is on and is required for the formula to work
-
var text qbRealm = NotRight(NotLeft(URLRoot(), 8), "/")
- Constructs the URL, which is needed for the formula to function
"https://api.quickbase.com/v1/docTemplates/" & $templateId &"/generate?&tableId=" & $tableId & "&realm=" & $qbRealm & "&filename=" & $fileName & "&format=" & $format &"&recordId=" & ToText($recordId)
Other methods to generate documents
The Document Creation formula is an advanced formula that makes an API call.
The easiest way to implement Document Creation is to add the formula to a formula-url field on your table and then add that field to reports or forms.
However, you can also create API calls and use Pipelines, code pages, or custom integrations to generate documents. Each part of the formula represents an API parameter.
- Learn more about Extending Quickbase
- Read API documentation for generating documents