Common DSL & Mapper Patterns
Common DSL & Mapper Patterns
Practical recipes for DSL and Data Mapper patterns that come up constantly in real builds. Each pattern includes a use case and a working example you can adapt.
For the full function references, see the DSL Reference and the Data Mapper Reference.
String Constants in YAML (Why Triple Quotes?)
Before diving into patterns, you need to understand how constants work in compound action YAML. This is the single most confusing syntax element for new builders.
In compound actions and data mappers, bare values are treated as data bank references, not strings. If you write:
The system looks for data.approved in the data bank — it does NOT pass the string "approved". To pass a literal constant, you need quotes.
The quoting rules
Why triple quotes?
This is standard YAML quoting interacting with DSL evaluation:
- Outer single quotes (
'...') tell YAML to treat the content as a literal string (no YAML processing) - Inner single quotes (
'...') are the DSL string delimiter - So
'''approved'''is YAML for: the DSL expression'approved', which evaluates to the string constantapproved
When do you NOT need quotes?
When referencing the data bank — that’s the default behavior:
Data Mapper Patterns
Omit null or empty keys from a payload
APIs often reject requests with null fields. Use EVAL() with $FILTER to build an object and strip out any keys that are null or empty before sending.
Use case: Building a calendar event payload where recurrence and location are optional.
If location and recurrence are null, they disappear from the payload entirely.
Transform a list of objects
Use MAP() to reshape each item in an array — rename fields, flatten nested values, or add computed fields.
Use case: Rename API field names to user-friendly names for SDA.
Conditionally include a field
Use CONDITIONAL() to include a field only when a condition is met — useful for building dynamic query filters.
Use case: Only add a date filter to a SOQL query when the user provided a date.
Merge data from multiple actions
Use MERGE() to combine objects from different action outputs into a single result — useful for compound actions that fetch from multiple sources.
Use case: Combine user data from one action with company data from another.
Map a code to a human-readable label
Use LOOKUP() when an API returns status codes or category IDs that need to be translated for the user.
Use case: Convert ServiceNow incident state numbers to labels.
Build a dynamic URL
Use RENDER() or $CONCAT to construct URLs from dynamic data — for linking back to source records.
Use case: Generate a clickable link to a ServiceNow ticket.
Sort results
Use SORT() to order an array by a field.
Add reverse: 'true' for descending order.
DSL Patterns
Validate a date is in the future
Use in a slot validation policy to reject past dates.
Validate a date is within a range
Check that a date is at least 7 days from now (e.g., for travel booking lead time).
Check if a value is in a list
Use in for allowlist/blocklist validation.
Or with $ANY for more complex matching:
String formatting and transformation
Chain string functions for normalization:
Build a full name from parts:
Serialize an object to a string
When passing structured data to mw.generate_text_action (which only accepts string input), use $STRINGIFY_JSON:
Count items matching a condition
Conditional logic in compound action switch expressions
Use comparison operators in switch conditions:
Combined Patterns
These patterns use both DSL expressions inside Data Mappers.
Dynamic message with data from multiple sources
Use RENDER() (mapper) with DSL expressions in the args:
Filter and transform in one step
Use DSL $FILTER inside a mapper MAP():