Loading
Ongoing maintenance for Salesforce HelpRead More
Salesforce Document Generation
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Create a Formula-Based Transformation for Document Generation

          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:

          1. Create a quote with quote line items that include Quantity and Unit Price values.
            Quote line items showing Quantity and Unit Price values used to calculate total price.
          2. Open the context definition.
          3. Add nodes.
            Each node represents a dataset that’s processed independently in DPE and later combined into a single output.
            1. Quote
            2. Quote Line Item
              Context Definition showing Quote and Quote Line Item nodes.
          4. 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.
            Field mapping for Quote Line Item showing Quantity and Unit Price fields.
          5. 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.
          6. Create a Formula node.
            1. Define the formula as Quantity × Unit Price.
            2. Set the alias as Price.
            3. Configure the output field type as Number.
            4. 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.
          7. 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
          8. 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.
            1. Quote Writeback
              • For Source Node, select Quote
              • For JSON Structure, select Simple
              • For Target Type, select JSON
            2. 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
          9. Configure a Composite Writeback node.
            Composite Writeback combines parent and child data into a single structured JSON output required for document generation.
            1. Define the sequence as Quote → Quote Line Item
            2. Map Parent Field to Quote ID
            3. Map Node Field to Parent Reference
            4. For Target Type, select JSON
          10. Save and activate the transformation.
            Composite Writeback configuration showing sequence from Quote to Quote Line Item with parent reference mapping.
          11. Generate a document using the transformation.
            1. In the document template, for Context Transformation Name, select the transformation.
            2. 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.
            3. For the input, enter the Quote ID.
              The Quote ID acts as the Context Instance Identifier to retrieve and transform data at run time.
            4. Generate the document.
              Generated document displaying calculated price for each line item based on Quantity and Unit Price.
           
          Loading
          Salesforce Help | Article