You are here:
Create a Formula-Based Transformation for Document Generation
Calculate derived values such as total price.
Required Editions
| Available in: Lightning Experience |
| Available in: Professional, Enterprise, Unlimited, and Developer Editions |
| User Permissions Needed | |
|---|---|
| To configure formula-based transformation for document generation: | DocGen Designer with Admin Persona |
Use Case: A quote contains line items with Quantity and Unit Price. Use a formula-based transformation to calculate the total price for each line item and show the calculated value in the document output. The system doesn’t store the calculated value in the source data and derives it dynamically during transformation.
Before you begin:
- Make sure that you’ve Set Up Data Transformation for Document Generation.
- Make sure you’ve a document template that includes tokens for Quantity, Unit Price, and the calculated field (Price).
-
Create a quote with quote line items that include Quantity and Unit Price values.
- Open the context definition.
-
Add nodes.
Each node represents a dataset that’s processed independently in DPE and later combined into a single output.
- Quote
-
Quote Line Item
-
Map required fields in Quote Line Item, including Quantity and Unit Price.
These fields are required to compute the formula and map the calculated value back to the correct line item.
-
From the Transform tab, select the transform you created.
When you open the DPE definition from the Transform tab, the Data Source node is preconfigured with the context data structure. It uses context as the source type, the selected context definition as the source object. It retrieves context data at run time based on the provided identifier, such as a Quote ID.The Data Source node and Data Source Subtype nodes are preconfigured and mapped to the context definition to retrieve context data at run time by using the Context Instance Identifier, such as the Quote ID.
-
Create a Formula node.
- Define the formula as Quantity × Unit Price.
- Set the alias as Price.
- Configure the output field type as Number.
- Add Quote Line Item ID as the identifier field.
The formula node calculates values that aren’t present in the source data. The identifier field makes sure that the calculated value is associated with the correct line item. The alias defines the field name in the output JSON and must match the token used in the document template. Use a consistent and meaningful alias, because this name is carried through join, writeback, and template rendering. If the alias doesn’t match, the value isn’t rendered in the document. -
Configure a Join node to merge the calculated value with the original dataset.
Without join, the calculated field isn’t included in the final JSON output used by the template. The join preserves the alias defined in the formula node and makes the calculated field available for writeback.
- Join the formula node with the Quote Line Item subtype node
- Use Quote Line Item ID to merge the calculated value with the corresponding record
-
Configure JSON writebacks.
Writebacks define the final JSON structure returned to DocGen. Including the calculated field ensures that the template can access and render the derived value. Make sure that the field name used in the writeback matches the alias defined in the formula node.
-
Quote Writeback
- For Source Node, select Quote
- For JSON Structure, select Simple
- For Target Type, select JSON
-
Quote Line Item Writeback
- Set Source Node to the join node
- Include the calculated Price field from the join node
- For Target Type, select JSON
-
Quote Writeback
-
Configure a Composite Writeback node.
Composite Writeback combines parent and child data into a single structured JSON output required for document generation.
- Define the sequence as Quote → Quote Line Item
- Map Parent Field to Quote ID
- Map Node Field to Parent Reference
- For Target Type, select JSON
-
Save and activate the transformation.
-
Generate a document using the transformation.
- In the document template, for Context Transformation Name, select the transformation.
-
Configure the template to show details such as Quantity, Unit Price, and the calculated
Price field.
The template must reference the calculated field by using the alias defined in the formula node. The alias must exactly match the field name in the JSON output.
-
For the input, enter the Quote ID.
The Quote ID acts as the Context Instance Identifier to retrieve and transform data at run time.
-
Generate the document.
Did this article solve your issue?
Let us know so we can improve!

