applyCurrentDocumentTo constraint, document scoping behavior for root and downstream entity types, and how filtering interacts with expansion paths and new entity creation.
Document Filtering Overview
applyCurrentDocumentTo constraint is defined on a data source, Powersheet automatically restricts results to items that belong to the LiveDoc in which the widget is rendered. The filter operates by matching the document’s moduleFolder and moduleName properties against the current LiveDoc context.
applyCurrentDocumentTo Constraint
TheapplyCurrentDocumentTo property is defined within the constraints block of a data source configuration. It specifies which entity type should be restricted to only items contained within the current LiveDoc.
Constraint Properties Reference
Constraints on entity types combine with constraints defined on relationships. When both an entity type and a relationship define project or document constraints, they are merged with AND logic before query execution.
Root Entity Filtering
WhenapplyCurrentDocumentTo matches the root entity type specified in query.from, the document filter applies directly to the primary query. This is the most common pattern: the sheet displays items of a single type that live in the current document.
SystemRequirementis both the root query entity and the document-filtered entity- Only
SystemRequirementitems that belong to the current LiveDoc are returned - Expanded
DesignRequirementitems are fetched through the relationship regardless of which document they belong to
How Root Filtering Works
- The widget reads the current LiveDoc context (module folder and module name)
- The constraint system detects that
applyCurrentDocumentTomatches thequery.fromentity type - A document filter predicate is automatically injected into the query’s where clause
- The query returns only items from the specified document
Downstream Entity Filtering
WhenapplyCurrentDocumentTo targets a related entity type (not the root query.from entity), the constraint applies to the downstream entity within the expansion path. The root entity type is queried without document restriction.
UserNeedis the root entity type and is not document-filteredSystemRequirementis the downstream entity type scoped to the current document- The sheet shows all
UserNeeditems matching the where clause, but only expands toSystemRequirementitems that belong to the current LiveDoc
Downstream Filtering Scenarios
Document Context Variables
When document filtering is active, the following context information is available for use within query expressions and dynamic value resolution:
These variables are automatically populated when the Powersheet widget is rendered inside a LiveDoc. They are used internally by the document filter and are also available via
$context.document.id expressions in dynamic value configurations.
The exact format of
document.id depends on the Polarion space configuration. For documents in the default space (_default), the space prefix may be omitted from the document ID.Document Filtering with New Entities
WhenapplyCurrentDocumentTo is configured and a user creates a new entity through the sheet, the document constraint is automatically applied to the new item’s initial values. This ensures newly created items are scoped to the current document without manual intervention.
SystemRequirement through the sheet, it is automatically placed in the current LiveDoc.
Constraint Propagation
Document constraints defined on entity types propagate to related navigation properties during query expansion. This propagation determines how document scoping applies across the full expansion path.
When both an entity type and its relationship define document constraints, the system merges them. For many-to-many relationships traversed through association types, the constraint resolver unwraps the association to reach the target entity type and applies the combined constraint there.
Data Model Constraint Configuration
Document constraints can also be defined at the entity type level in the data model YAML, independent of the sheet configuration’sapplyCurrentDocumentTo. These constraints apply to all queries against the entity type across every sheet configuration that references the model.
Data model constraints (
load, pick, create) define static document filters based on known folder or document names. In contrast, applyCurrentDocumentTo is dynamic — it uses the current LiveDoc context at runtime. Both mechanisms can coexist; they are combined with AND logic.Complete YAML Example
The following example demonstrates a full sheet configuration with document filtering applied to a requirements traceability matrix (RTM):- User Needs source with root-level document filtering on
UserNeedand a three-level expansion path:UserNeed>SystemRequirement>DesignRequirement - Hazards source with root-level document filtering on
Hazardand a single-level expansion toRiskControl
Interaction with Other Constraints
Document filtering viaapplyCurrentDocumentTo works alongside other constraint types defined in the data model and sheet configuration:
Constraint Resolution with Navigation Properties
When document filtering targets a downstream entity type, the constraint must be resolved through the expansion path. The system resolves the path from the root entity type to the filtered entity type by traversing navigation properties defined in the data model.UserNeed > systemRequirements > systemRequirement, the constraint resolver:
- Starts at the root entity type (
UserNeed) - Follows the
systemRequirementsnavigation property (direct direction) - Reaches
SystemRequirementand applies the document filter
systemRequirements.systemRequirement.designRequirements) for deep navigation hierarchies.
Behavior Without Document Context
When the Powersheet widget is rendered outside a LiveDoc context (for example, in a Wiki page or a standalone widget), the document filter has no effect:Related Pages
- EntityQuery — query structure and
fromclause reference - Predicates — where clause predicate syntax
- Expand Clause — expansion path configuration
- Query Context — context variables and parameter passing
- Constraints — data model constraint definitions
- Sources — data source configuration reference
- Navigation Directions — direct and back relationship traversal