Function expressions

What a function expression is

A function expression is a reusable, named function that produces content when a document renders. Unlike a merge field, it does not need an underlying record value. It generates its output, for example the current date, a computed clause, or a signature placeholder.

Function expressions are stored as Function_Expression__c records. Each has a Name and a Function body.

The function body

The function body is an expression that evaluates to a function, usually an arrow function. The function runs when the document renders, and what it returns is the content to insert:

// CurrentDate
(args) => new Date().toLocaleDateString("en-GB");

A body written as statements, such as return new Date();, is not a function and renders empty. The CurrentDate record created by a fresh install uses that statement form, so replace its Function body with the arrow function above before using it.

Function names may contain only letters, digits and underscores. Never create a record named Signature: it replaces the built-in signature function described below.

Functions can return text or markup, and can compute their result at render time. The returned content is placed into the document where the function expression sits.

Using a function expression

In the builder, open the Functions dropdown in the toolbar and pick a function. It inserts a chip and copies the expression for pasting:

#{Functions:CurrentDate}
#{Functions:MyCustomClause}

At render, the named function runs and its output replaces the chip.

The built-in signature function

The Functions dropdown always offers a built-in Signature function:

#{Functions:Signature}

This renders a signature drop zone in the document. When the recipient signs, their captured signature is placed into it. A signature expression is assigned to one of the signers using the Submitters dropdown on the chip's toolbar, so in a multi-signer document each signature block belongs to the right party.

Combining with a formatter

A function's output can be passed through a value formatter, the same way a merge field can:

#{Functions:CurrentDate>EUDateFormat}

Here the current date is generated, then formatted as dd/mm/yyyy.

Creating and managing functions

Manage functions from the Function Expressions tab, or create one from the Functions dropdown in the builder. Give it a clear Name, since templates reference it by Name, and a function body that returns the content.

Conditional content

Alongside function expressions, any element in a document can carry a condition that decides whether it renders. If the condition is not met, the element is removed at render time. This lets you show or hide clauses, rows, or blocks based on the record's data, without duplicating templates.

Difference from value formatters

A function expression produces content. A value formatter reshapes a value you are already merging. Use a function to generate, and a formatter to format.

Tips