Prerequisites
- A working data model with entity types and relationships already defined
- At least one relationship with
directandbacknavigation properties configured - Familiarity with the three constraint stages (
load,pick,create) covered in Configure Constraints
How Context Expressions Work
A context expression uses the$context prefix followed by a dot-notation property path. Powersheet resolves this path at runtime by reading the current row’s source entity properties. Unlike static constraint values, context expressions produce different filter results per row depending on each source entity’s document.
Context expressions (
$context.property.path) are used only in data model YAML — specifically inside constraints blocks. They support dot-notation property access but not JavaScript logic. For dynamic expressions in sheet configuration YAML (sources, columns, formatters), use the () => expression syntax instead. See Configure Dynamic Expressions for that approach.Available Context Paths
The$context object provides access to the source entity’s document properties. These are the paths you can use:
| Path | Description | Example Value |
|---|---|---|
$context.source.type | Source entity’s work item type | "sys_req" |
$context.source.document.id | Source entity’s document ID | "Requirements/SRS" |
$context.source.document.moduleName | Source entity’s document module name | "UserNeedSpecification" |
$context.source.document.moduleFolder | Source entity’s document folder | "Requirements" |
$context.source.document.component | Source entity’s document component | "Braking" |
$context.source.document.type | Source entity’s document type | "systemRequirementsSpecification" |
$context.source.document.title | Source entity’s document title | "System Requirements" |
Filter by Document Component
The most common use case is scoping relationship pickers by the source entity’s document component. This prevents users from accidentally linking to entities outside their subsystem.Add a With this constraint, when viewing a
$context reference inside the constraint document block on the appropriate relationship direction:SystemRequirement in a document with component “Braking”, only DesignRequirement items from “Braking” documents will be loaded as children.Filter by Document Name and Folder
To restrict linked items to the exact same document as the source entity, combine This pattern is useful in projects where each document represents a self-contained specification, and traceability should stay within document boundaries.
moduleName and moduleFolder:Apply Context Constraints to Pick and Create Stages
Context expressions work across all three constraint stages. Apply them to In this configuration:
pick to scope the relationship picker dialog, or to create to control where new items are created:- load: only hazards from the same component appear in the sheet
- pick: the picker shows items from documents of the same type as the source
- create: new hazards are created in the same folder as the source document
Apply Context Constraints at Entity Type Level
Context expressions can also be placed on
domainModelTypes entries (not just relationships). This applies the constraint globally whenever that entity type is loaded, picked, or created:Combine Context and Static Constraints
You can mix This restricts the picker to items that are both in
$context expressions with static values in the same constraint block. Static values act as fixed filters while context values adapt per row:systemRequirementsSpecification documents and in the same component as the source entity’s document.Common Patterns
| Scenario | Context Path | Constraint Example |
|---|---|---|
| Same component | $context.source.document.component | component: $context.source.document.component |
| Same document | $context.source.document.moduleName | moduleName: $context.source.document.moduleName |
| Same folder | $context.source.document.moduleFolder | moduleFolder: $context.source.document.moduleFolder |
| Same document type | $context.source.document.type | type: $context.source.document.type |
| Same document (exact) | $context.source.document.id | id: $context.source.document.id |
Complete YAML Example
Below is a full data model snippet demonstrating context constraints across entity types and relationships in a standard RTM hierarchy:Verification
After saving the data model with context constraints:- Open a sheet that uses this data model
- Navigate to a row whose source entity belongs to a specific document component (e.g., “Braking”)
- For load constraints: verify that child rows show only entities from the same component
- For pick constraints: click a relationship picker cell and confirm the dropdown shows only items matching the source entity’s document properties
- Compare two rows from different components — each should show different filtered results based on its own source entity context
- The
$contextpath is spelled correctly (case-sensitive) - Source entities actually have different document component/folder values in Polarion
- The constraint is placed on the correct relationship direction (
directorback)
See Also
- Configure Constraints — static constraint stages, operators, and logical composition
- Configure a Relationship — setting up the relationships that context constraints filter
- Configure Dynamic Expressions —
() => expressionsyntax for sheet configuration YAML - Data Model Reference — complete property reference for data model YAML
- Create Bidirectional Links — establishing the
directandbacknavigation properties used in constraints