Custom Functions
While SignStack provides powerful built-in capabilities with JSONata expressions, you'll often have complex business logic or calculations that you need to reuse across multiple Templates or Blueprints. Custom Functions provide an elegant solution for this.
What are Custom Functions? 🧩
A Custom Function is a reusable, versioned snippet of JSONata logic that you define once and can then call from anywhere within your SignStack expressions. Think of them as creating your own private library of helpers tailored to your specific business rules.
-
Encapsulation: They allow you to encapsulate complex logic (like calculating a region-specific tax rate or formatting a complex address string) into a single, named function.
-
Reusability: Define the logic once and call it by its unique
keyfrom anyvalueExpression,displayCondition, oronCompleteMapperacross your entire workspace. This promotes consistency and dramatically reduces redundancy. -
Maintainability: If your business logic changes, you only need to update the
Functiondefinition in one place. You can release a new version, and (thanks to semantic versioning) your existingBlueprintsandTemplatescan safely adopt the changes or be updated intentionally.
Defining a Function
Each Function is a reusable asset with key properties:
-
key: The unique,camelCasename you use to call the function in your expressions (e.g.,calculateSalesTax). -
displayName: A human-readable name for the UI (e.g., "Calculate Sales Tax"). -
version: A semantic version string (e.g.,"1.0.0") to manage changes safely. -
params: (Optional) Defines the input parameters the function expects. -
returnType: Defines the expected output type. -
body: The actual JSONata expression that performs the function's logic.
Using a Function
Once defined, using a custom function within another expression is simple. You just call it by its key, passing any required parameters.
Example valueExpression using a custom function:
// Assuming you have a function with key 'calculateSalesTax'
// that takes the amount and state code as parameters.
"$formatNumber($calculateSalesTax(entities.dealInfo.amount, entities.clientInfo.state), '$,0.00')"
Custom Functions are a powerful tool for keeping your Blueprints and Templates clean, readable, and maintainable by encapsulating complex, reusable business logic.
You manage your Functions using the /jsonata-functions API or the "Functions" section in the dashboard.
➡️ Next: Core Concepts: Scenarios (Design, Preview, Test)