Why Dynamic Expressions Matter
Consider a data model whereDesignRequirement entities link to SystemRequirement entities. Without dynamic expressions, a constraint that filters design requirements to a specific component would need to be hardcoded:
Two Notations, Two Worlds
Powersheet uses two distinct expression notations. Each belongs to a different configuration file type, and they are not interchangeable.Context Expressions: Property Path Traversal
Context expressions ($context.property.path) are declarative lookups. Think of them as a pointer into a data structure — no logic, no computation, just “go to this address and return what you find.”
Powersheet resolves a $context expression by walking the dot-separated segments at runtime. The expression $context.source.document.component means: start at the context object, navigate to source, then document, then read the component property.
This simplicity is intentional. Data model constraints define structural rules about which entities can relate to each other. They should be predictable and side-effect-free. A constraint that runs arbitrary JavaScript could introduce subtle bugs across the entire traceability structure.
Available paths for $context:
Dynamic constraints with
$context are evaluated per-row. If your sheet displays system requirements from multiple components, each row resolves $context.source.document.component independently. Row A might resolve to “Braking” while Row B resolves to “Steering.”Dynamic Values: JavaScript Arrow Functions
Dynamic values (() => expression) bring full JavaScript expressiveness to sheet configuration. They can access multiple context properties, perform calculations, construct strings, render HTML, control display values for navigation properties, and apply conditional logic.
The () => syntax is a JavaScript arrow function that receives a context object. At runtime, Powersheet evaluates the function and uses the returned value:
The Context Object
Both expression notations draw from a shared runtime context object. Understanding its structure is the key to writing correct expressions. The context is hierarchical — properties are progressively available depending on where the expression is evaluated.
Think of this as a funnel: at the query level (
where), there is no “current item” yet — the query finds items. At the cell level (formula, render, display), each expression runs in the context of a specific item and cell value.
Where Each Notation Is Used
Context Expressions in Data Model Constraints
Context expressions appear exclusively in data model constraint definitions — the rules that control which entities can be loaded or picked when navigating relationships.SystemRequirement to show linked DesignRequirement entities, only load those from documents matching the source’s component. The constraint is structural — it shapes what data appears in the sheet.
For more on how constraints work in the data model, see Process Constraints and Entity Types and Relationships.
Dynamic Values in Sheet Configuration
Dynamic values appear across several sheet configuration properties, each serving a different purpose:Formatter Expressions: The Exception
Formatter expressions use a simplified syntax that differs from both$context and () =>:
() => prefix, no $context prefix. The expression is evaluated directly as a boolean condition. This is a deliberate design choice — formatters only need to answer “does this condition match?” and the simplified syntax makes that intent clear.
Common Expression Patterns
Controlling How Navigation Properties Display
The most common use of() => is the display property on navigation columns — it controls which field of a linked entity appears in the cell. For columns that show a referenced document, display: titleOrName is the typical choice; for columns that show a chapter or section reference, use display: title:
display runs in a cell context, context.value is the linked entity itself, and the arrow function picks the human-readable label without mutating any data. This pattern keeps the underlying binding intact (so navigation, sorting, and saving still work against the real entity) while letting each column choose the most meaningful label.
Scoping a Query to the Current Document
A commonwhere pattern is to restrict a sheet to entities that live in the same document as the powersheet widget. Use context.document.moduleName so the query follows whichever document the user has open:
Calculating Derived Values
Formulas can reference any property on the current item:Dynamic Initial Values
When users create new entities from within the sheet,entityFactory sets sensible defaults — often by inheriting from the current document:
Custom Cell Rendering
Renderers produce HTML for rich cell content:Date Comparisons
JavaScript Date objects work naturally in where clauses:Date values must be in the correct format for the target data type. For Polarion date fields,
.toISOString() produces the expected format.Mental Model: Static Structure vs Dynamic Behavior
The two expression types reflect a fundamental architectural division in Powersheet:-
The data model defines what exists — entity types, relationships, cardinality rules. It is the structural blueprint. Context expressions (
$context) fit here because they are declarative property lookups that shape data boundaries. -
The sheet configuration defines how things look and behave — column layout, formatting, calculations, rendering, and the labels shown for navigation properties. Dynamic values (
() =>) fit here because they need the full expressiveness of runtime computation.
Quick Reference
Further Reading
- Process Constraints — how constraints control entity loading and picking in the data model
- YAML Configuration System — the overall configuration architecture that expressions plug into
- Data Model vs Sheet Configuration — why the two configuration files exist and how they interact
- Navigation Properties — how expansion paths and the
displayproperty work together - Sheet Configuration Guides — practical step-by-step instructions for configuring columns, formatters, and queries
- Customization Guides — hands-on guides for custom fields and conditional formatting