> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/visual-template-editor/advanced-data-formula-builder.md).

# Advanced Data: Formula Builder

Formula variables allow you to evaluate complex logic, perform calculations, and render dynamic values directly within your document templates using standard Salesforce operators and functions.

#### Before You Begin

Open your target document template inside the S-Docs template builder.

#### Creating a Formula Variable

{% columns %}
{% column width="41.66666666666667%" %}

<figure><img src="https://1548664070-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWKNnJmhJBQwhdk5WBFsi%2Fuploads%2FybW6oeLPvOT1gmdbxj3Y%2FScreenshot%202026-08-27%20at%2010.28.59%E2%80%AFAM.png?alt=media&amp;token=f45d902a-73c6-41bc-b5dd-c0658e632c39" alt=""><figcaption><p><em>Advanced Variables Panel</em></p></figcaption></figure>

<figure><img src="https://1548664070-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWKNnJmhJBQwhdk5WBFsi%2Fuploads%2FAdFcL6nww8BQjXiggSHT%2FScreenshot%202026-08-27%20at%2010.21.35%E2%80%AFAM.png?alt=media&amp;token=fb44e366-3f9f-4401-b321-ee07dbb56f24" alt=""><figcaption><p>Configure Formula Panel</p></figcaption></figure>
{% endcolumn %}

{% column width="58.33333333333333%" %}

1. Navigate to the main variables panel and select the *Advanced Variables* ![](https://1548664070-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWKNnJmhJBQwhdk5WBFsi%2Fuploads%2FfHmGPqkktApUvNhxTSip%2FScreenshot%202026-07-07%20at%204.20.58%E2%80%AFPM.png?alt=media\&token=67ebb578-3ffe-4b40-b919-5c861c80e2b6) icon located at the top of the panel.
2. In the right-side drawer, select *Formulas*.
3. Select *Click to* *add* under the Formulas section to launch the configuration panel.
4. Enter a custom name for your variable in the *Label* field.
5. Select a data type from the *Return Type* dropdown menu. String is selected by default. Available options include:
   * String
   * Checkbox
   * Currency
   * Date
   * Date Time
   * Decimal
   * Integer
   * Percent
   * Time
6. Click Configure Formula to open the formula builder.
   {% endcolumn %}
   {% endcolumns %}

<figure><img src="https://1548664070-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWKNnJmhJBQwhdk5WBFsi%2Fuploads%2F362MO09nbzI91WhZ9pLe%2FScreenshot%202026-08-27%20at%2010.22.05%E2%80%AFAM.png?alt=media&amp;token=be19e67a-91f4-47db-8d9b-6f698f7158e7" alt=""><figcaption></figcaption></figure>

7. Build your expression using standard object fields, operators, and functions:
   * Click Insert Field to search or select fields from the current object record.
   * Select standard Salesforce operators from the *Operators* dropdown menu.
   * Choose functions from categories including math, text, date and time, logical, and advanced.
8. Select **Validate** to verify your formula syntax is correct.

{% hint style="warning" %}
Formulas can not be saved if the syntax is invalid.
{% endhint %}

9. Click **Confirm** once the formula is validated.
10. Click **Add Formula** in the configuration panel to save the item to your library.

#### Inserting a Formula Variable Into a Template&#x20;

Once created, formula variables appear in the main variables panel under the *Formulas* category. They are grouped by their assigned return type — such as text, date, or time — and function identically to standard variables.

* Open the main variables panel ![](https://1548664070-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWKNnJmhJBQwhdk5WBFsi%2Fuploads%2FXZtitwYuD2Qrulrfmk4O%2FScreenshot%202026-07-07%20at%204.18.58%E2%80%AFPM.png?alt=media\&token=79715bcf-be59-48b8-bd2f-1b8f2061fb0e) and navigate to the *Formulas* category.
* Select and insert your formula variable into the template body.

{% hint style="info" %}
Upon document generation, S-Docs evaluates your formula logic and automatically renders the output.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.sdocs.com/sdocs/visual-template-editor/advanced-data-formula-builder.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
