Skip to main content
This reference covers the 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

diagram
Document filtering is a constraint-based mechanism. When the 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

The applyCurrentDocumentTo 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.
Use applyCurrentDocumentTo whenever the Powersheet widget is embedded in a LiveDoc and you want the sheet to display only items that belong to that specific document. Without this constraint, the query returns all matching items across the entire project.

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

When applyCurrentDocumentTo 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.
In this configuration:
  • SystemRequirement is both the root query entity and the document-filtered entity
  • Only SystemRequirement items that belong to the current LiveDoc are returned
  • Expanded DesignRequirement items are fetched through the relationship regardless of which document they belong to

How Root Filtering Works

  1. The widget reads the current LiveDoc context (module folder and module name)
  2. The constraint system detects that applyCurrentDocumentTo matches the query.from entity type
  3. A document filter predicate is automatically injected into the query’s where clause
  4. The query returns only items from the specified document

Downstream Entity Filtering

When applyCurrentDocumentTo 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.
In this configuration:
  • UserNeed is the root entity type and is not document-filtered
  • SystemRequirement is the downstream entity type scoped to the current document
  • The sheet shows all UserNeed items matching the where clause, but only expands to SystemRequirement items that belong to the current LiveDoc
The entity type name specified in applyCurrentDocumentTo must be a valid entity type defined in the referenced data model. If the entity type is not found, the constraint is silently ignored and no document filtering is applied.

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

When applyCurrentDocumentTo 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.
With this configuration, when a user adds a new 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’s applyCurrentDocumentTo. 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.
See Constraints for the full constraint configuration reference.

Complete YAML Example

The following example demonstrates a full sheet configuration with document filtering applied to a requirements traceability matrix (RTM):
This configuration defines two data sources:
  1. User Needs source with root-level document filtering on UserNeed and a three-level expansion path: UserNeed > SystemRequirement > DesignRequirement
  2. Hazards source with root-level document filtering on Hazard and a single-level expansion to RiskControl
Both sources restrict their root entity type to items within the current LiveDoc while allowing expanded entities to come from any document.

Interaction with Other Constraints

Document filtering via applyCurrentDocumentTo works alongside other constraint types defined in the data model and sheet configuration:
When both an entity type and its relationship define document constraints, the constraints are combined. Ensure that the constraint definitions do not conflict or create overly restrictive filters that return empty results.

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.
For the expansion path UserNeed > systemRequirements > systemRequirement, the constraint resolver:
  1. Starts at the root entity type (UserNeed)
  2. Follows the systemRequirements navigation property (direct direction)
  3. Reaches SystemRequirement and applies the document filter
The resolution supports multi-level dot-notation paths (e.g., 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:
When developing sheet configurations outside a LiveDoc, remember that document filtering is inactive. Validate filtering behavior by embedding the widget in the target LiveDoc.


Last modified on July 10, 2026