> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nextedy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Expressions Reference

> Nextedy POWERSHEET configurations support **dynamic value expressions** -- values resolved at runtime based on the current context such as the active document, the logged-in user, URL parameters, or the source entity.

export const LastReviewed = ({date}) => {
  if (!date) return null;
  const formatted = new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric",
    timeZone: "UTC"
  });
  return <p className="mt-10 text-sm text-gray-400 dark:text-zinc-500 not-prose">
      Last reviewed on {formatted}
    </p>;
};

See also: [Constraints](/powersheet/reference/data-model/constraints) | [Properties](/powersheet/reference/data-model/properties) | [Relationships](/powersheet/reference/data-model/relationships) | [Binding Syntax](/powersheet/reference/sheet-config/binding-syntax)

## Two Expression Notations

Powersheet uses two distinct expression notations depending on the configuration layer:

<Frame>
  <img src="https://mintcdn.com/none-17b4493f/-WiVljKlDztH36bB/powersheet/diagrams/reference/data-model/context-expressions/diagram-1.svg?fit=max&auto=format&n=-WiVljKlDztH36bB&q=85&s=2e5ce956a4e55fdb64a7bb2de0bdd5c3" alt="diagram" style={{ width: "640px", maxWidth: "100%" }} width="640" height="220" data-path="powersheet/diagrams/reference/data-model/context-expressions/diagram-1.svg" />
</Frame>

| Notation               | Syntax                   | Used In                                                  | Expressiveness                    |
| ---------------------- | ------------------------ | -------------------------------------------------------- | --------------------------------- |
| **Context expression** | `$context.property.path` | Data model configuration (constraints)                   | Dot-notation property access only |
| **Dynamic value**      | `() => expression`       | Sheet configuration (`where`, `formula`, `render`, etc.) | Full JavaScript arrow function    |

<Tip title="Rule of thumb">
  If you are editing a **data model** YAML file (`domainModelTypes`, `relationships`), use `$context`. If you are editing a **sheet configuration** YAML file (`sources`, `columns`, `formatters`), use `() =>`.
</Tip>

***

## Context Expression (`$context`)

Context expressions use dot-notation to access properties from the runtime context. They are used exclusively in **data model configuration** -- specifically within [constraint](/powersheet/reference/data-model/constraints) definitions on entity types and relationships.

### How It Works

A `$context` expression is a property path that Powersheet resolves by traversing the context object at runtime. No JavaScript logic is supported -- only direct property access via dot-separated keys.

### Where It Is Used

| Configuration Location               | Description                                                          |
| ------------------------------------ | -------------------------------------------------------------------- |
| `domainModelTypes.*.constraints`     | Entity type constraints -- scopes `load`, `pick`, or `create` stages |
| `relationships.*.direct.constraints` | Direct-direction relationship constraints                            |
| `relationships.*.back.constraints`   | Back-direction relationship constraints                              |

### Available Context Paths

| Path                                    | Type     | Description                             | Example Value                       |
| --------------------------------------- | -------- | --------------------------------------- | ----------------------------------- |
| `$context.source.type`                  | `string` | Source entity's Polarion work item type | `"sys_req"`                         |
| `$context.source.document.id`           | `string` | Source entity's document ID             | `"Requirements/SRS"`                |
| `$context.source.document.moduleName`   | `string` | Source entity's document module name    | `"UserNeedSpecification"`           |
| `$context.source.document.moduleFolder` | `string` | Source entity's document folder path    | `"Requirements"`                    |
| `$context.source.document.component`    | `string` | Source entity's document component      | `"Braking"`                         |
| `$context.source.document.type`         | `string` | Source entity's document type           | `"systemRequirementsSpecification"` |
| `$context.source.document.title`        | `string` | Source entity's document title          | `"System Requirements"`             |

<Info title="Per-row evaluation">
  Dynamic constraints with `$context` are evaluated **per-row**. Different rows can produce different constraint values depending on their source entity's properties. For example, a `UserNeed` in a "Braking" document produces different constraint values than one in a "Steering" document.
</Info>

### Context Expression Examples

**Filter linked items to the same document component as the source item:**

```yaml theme={null}
relationships:
  - from: DesignRequirement
    to: SystemRequirement
    back:
      name: designRequirements
      constraints:
        load:
          document:
            component: $context.source.document.component
```

When viewing a `SystemRequirement` from the "Braking" component, only `DesignRequirement` entities from "Braking" documents are loaded.

**Filter linked items to the same document as the source item:**

```yaml theme={null}
constraints:
  load:
    document:
      moduleName: $context.source.document.moduleName
      moduleFolder: $context.source.document.moduleFolder
```

This restricts loaded entities to the exact same LiveDoc document as the source entity, matching on both module name and folder.

**Filter picker options by source document type:**

```yaml theme={null}
constraints:
  pick:
    document:
      type: $context.source.document.type
```

When a user opens a picker dialog, only entities from documents matching the source entity's document type appear as options.

### Complete Data Model Example with Context Expressions

```yaml theme={null}
domainModelTypes:
  UserNeed:
    polarionType: user_need
    properties:
      description:
      severity:

  SystemRequirement:
    polarionType: sys_req
    properties:
      description:
      severity:

  DesignRequirement:
    polarionType: des_req
    properties:
      description:

relationships:
  - from: SystemRequirement
    to: UserNeed
    cardinality: many-to-many
    storage: linkedWorkItems
    linkRole: decomposes
    direct:
      name: userNeeds
    back:
      name: systemRequirements
      constraints:
        load:
          document:
            component: $context.source.document.component

  - from: DesignRequirement
    to: SystemRequirement
    cardinality: many-to-many
    storage: linkedWorkItems
    linkRole: decomposes
    direct:
      name: systemRequirements
    back:
      name: designRequirements
      constraints:
        load:
          document:
            moduleName: $context.source.document.moduleName
            moduleFolder: $context.source.document.moduleFolder
        pick:
          document:
            type: $context.source.document.type
```

In this model, `SystemRequirement` back-navigation to `DesignRequirement` entities filters by both module name and folder at load time, and additionally restricts picker results by document type.

***

## Dynamic Value (`() => expression`)

Dynamic values use JavaScript arrow function syntax and are used in **sheet configuration** YAML files. They provide full JavaScript expressiveness for computing values, filtering data, and rendering content at runtime.

### How It Works

A `() =>` expression is a JavaScript arrow function that receives a `context` object. Powersheet evaluates the function at runtime and uses the returned value. The expression must be wrapped in quotes within the YAML to preserve the arrow function syntax.

### Where It Is Used

| Sheet Configuration Property | Purpose                                          | Returns                           |
| ---------------------------- | ------------------------------------------------ | --------------------------------- |
| `sources.query.where`        | Filter data with dynamic predicates              | Value matching the predicate type |
| `sources.entityFactory`      | Set initial values for new items                 | Property value                    |
| `columns.*.formula`          | Calculate column values from other properties    | Computed value (persisted)        |
| `columns.*.render`           | Custom HTML rendering for cells                  | HTML string                       |
| `columns.*.display`          | Override display value for navigation properties | Display string                    |
| `renderers.*`                | Named renderer definitions                       | HTML string                       |
| `formatters.*.expression`    | Conditional formatting expressions               | Boolean                           |

<Warning title="formula vs render">
  `formula` affects **persisted data** -- the calculated value is saved back to the data source. Use `render` if you only need to change how a value is **displayed** without modifying the underlying data.
</Warning>

<Note title="Formatter expression syntax">
  Formatter expressions use a simplified syntax -- they do **not** start with `() =>`. The expression is evaluated as a boolean condition directly (e.g., `"context.item.Probability <= 99"`).
</Note>

### Context Availability by Location

Not all context properties are available in every location. The following table shows which context sub-objects are accessible in each usage location:

| Usage Location         | `.user` | `.sources` | `.document` | `.item` | `.value` | `.source` | `.entity` | `.parameters` |
| ---------------------- | ------- | ---------- | ----------- | ------- | -------- | --------- | --------- | ------------- |
| `where`                | ✅       | ✅          | ✅           | --      | --       | --        | --        | ✅             |
| `entityFactory`        | ✅       | ✅          | --          | --      | --       | --        | --        | ✅             |
| `formula`              | ✅       | ✅          | --          | ✅       | ✅        | ✅         | ✅         | ✅             |
| `render` / `renderers` | --      | --         | --          | ✅       | ✅        | --        | --        | --            |
| `formatter`            | --      | --         | ✅           | ✅       | ✅        | --        | --        | --            |
| `display`              | --      | --         | --          | ✅       | ✅        | ✅         | --        | --            |

### Dynamic Value Examples

**Where clause -- filter by current document:**

```yaml theme={null}
sources:
  - id: requirements
    query:
      from: Requirement
      where:
        document:
          moduleName:
            "==": "() => context.document.moduleName"
```

The sheet loads only `Requirement` entities whose `document.moduleName` matches the current document's module name, scoping results to the active LiveDoc.

**Where clause -- filter by today's date:**

```yaml theme={null}
where:
  DueDate:
    ">": "() => new Date().toISOString()"
```

<Tip title="Date format">
  The resulting value must be in the correct format for the data type. For date fields, use `.toISOString()` to produce the ISO 8601 string that Polarion expects.
</Tip>

**Where clause -- combine multiple parameters:**

```yaml theme={null}
where:
  Client:
    "==": "() => `${context.parameters.client} ${context.parameters.status}`"
```

Template literal syntax allows concatenating multiple URL parameters into a single filter value.

**Entity factory -- set initial value from the source entity type:**

```yaml theme={null}
sources:
  - id: design_requirements
    query:
      from: DesignRequirement
    entityFactory:
      sourceType: "() => context.source.type"
```

When a user creates a new `DesignRequirement` entity in this sheet, the `sourceType` field is automatically populated with the Polarion work item type of the parent/source entity.

**Formula -- calculate a value from other item properties:**

```yaml theme={null}
columns:
  totalPrice:
    formula: "() => context.item.quantity * context.item.unitPrice"
```

The `totalPrice` column value is computed by multiplying `quantity` by `unitPrice`. This calculated value is persisted to the data source.

**Renderer -- custom HTML output:**

```yaml theme={null}
renderers:
  linkedItems: "() => context.value.map((item) => `<b>${item.name}</b>`).join(', ')"
```

Renders each linked item name in bold, separated by commas.

**Display -- show a property of a linked entity:**

```yaml theme={null}
columns:
  systemRequirement.document:
    display: "() => context.document.title"
```

Instead of showing the raw document reference, the column displays the document's human-readable title.

**Formatter -- conditional styling:**

```yaml theme={null}
formatters:
  criticalHighlight:
    expression: "context.item.Probability <= 99"
    style: warningStyle
```

Applies `warningStyle` to cells where the `Probability` value is 99 or below. Note the simplified syntax without `() =>`.

***

## The Context Object

The context object provides runtime information to dynamic expressions. Its structure is hierarchical, with properties progressively available depending on the evaluation scope.

### Context Object Structure

| Property                         | Type     | Description                                                                                                             | Available In                                 |
| -------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- |
| `context.parameters`             | `object` | URL and configuration parameters as key-value pairs. Access individual parameters via `context.parameters.{paramName}`. | `where`, `entityFactory`, `formula`          |
| `context.parameters.{paramName}` | `string` | Individual URL parameter value (e.g., `context.parameters.client`)                                                      | `where`, `entityFactory`, `formula`          |
| `context.user`                   | `object` | Current logged-in Polarion user                                                                                         | `where`, `entityFactory`, `formula`          |
| `context.user.id`                | `string` | User's login ID                                                                                                         | `where`, `entityFactory`, `formula`          |
| `context.user.name`              | `string` | User's display name                                                                                                     | `where`, `entityFactory`, `formula`          |
| `context.sources`                | `object` | All configured data source definitions from the sheet configuration                                                     | `where`, `entityFactory`, `formula`          |
| `context.document`               | `object` | Current document information                                                                                            | `where`, `formatter`                         |
| `context.document.title`         | `string` | Document title                                                                                                          | `where`, `formatter`                         |
| `context.document.type`          | `string` | Document type                                                                                                           | `where`, `formatter`                         |
| `context.document.id`            | `string` | Document identifier                                                                                                     | `where`, `formatter`                         |
| `context.document.moduleName`    | `string` | Document module name                                                                                                    | `where`, `formatter`                         |
| `context.document.moduleFolder`  | `string` | Document folder path                                                                                                    | `where`, `formatter`                         |
| `context.document.component`     | `string` | Document component                                                                                                      | `where`, `formatter`                         |
| `context.tool`                   | `object` | Current tool information                                                                                                | See application                              |
| `context.tool.type`              | `string` | Tool type identifier                                                                                                    | See application                              |
| `context.item`                   | `object` | Current entity (row) with all its properties. Access fields via `context.item.{propertyName}`.                          | `formula`, `render`, `formatter`, `display`  |
| `context.source`                 | `object` | Parent/source entity in relationship contexts. Access its document via `context.source.document.*`.                     | `formula`, `display`, `$context` expressions |
| `context.entity`                 | `object` | Current entity as a plain object                                                                                        | `formula`                                    |
| `context.value`                  | `any`    | Current cell's display value                                                                                            | `formula`, `render`, `formatter`, `display`  |

### Context Tree Diagram

```
context
 +-- parameters          URL and configuration parameters (key-value pairs)
 |    +-- {paramName}     e.g., context.parameters.client
 +-- user                Current logged-in user
 |    +-- id
 |    +-- name
 +-- sources             All configured data source definitions
 +-- document            Current document information
 |    +-- title
 |    +-- type
 |    +-- id
 |    +-- moduleName
 |    +-- moduleFolder
 |    +-- component
 +-- tool                Current tool information
 |    +-- type
 +-- item                Current entity (per-cell contexts only)
 |    +-- {propertyName}  e.g., context.item.StoryPoints
 +-- source              Parent/source entity (relationship contexts)
 |    +-- {propertyName}  e.g., context.source.document.component
 +-- entity              Current entity as a plain object
 +-- value               Current cell's display value
```

<Info title="Scope-dependent availability">
  * `item`, `source`, `entity`, and `value` are only available in **per-cell** contexts (`formula`, `render`, `formatter`, `display`)
  * `document` is available in `where` clauses and `formatter` expressions
  * In `$context` expressions (data model constraints), only `source` and its sub-properties are available
</Info>

***

## Notation Comparison

The two expression systems serve complementary purposes. Understanding when to use each prevents configuration errors.

| Aspect                 | `$context` (Model)                              | `() =>` (Sheet)                                               |
| ---------------------- | ----------------------------------------------- | ------------------------------------------------------------- |
| **Syntax**             | `$context.source.document.component`            | `"() => context.document.moduleName"`                         |
| **Language**           | Dot-notation path (no logic)                    | JavaScript arrow function                                     |
| **Configuration file** | Data model YAML                                 | Sheet configuration YAML                                      |
| **Evaluation**         | Per-row, based on source entity                 | Per-cell or per-query, based on context scope                 |
| **Capabilities**       | Property path access only                       | Arithmetic, string interpolation, array methods, conditionals |
| **Use cases**          | Constraint scoping by document, type, component | Query filtering, calculated columns, custom rendering         |
| **YAML quoting**       | Not required                                    | Required (wrap in double quotes)                              |

***

## Quick Reference

| I want to...                                     | Notation   | Example                                                      |
| ------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| Filter relationship by source document component | `$context` | `component: $context.source.document.component`              |
| Filter relationship by source document module    | `$context` | `moduleName: $context.source.document.moduleName`            |
| Filter query by current document                 | `() =>`    | `"==": "() => context.document.moduleName"`                  |
| Calculate column from other fields               | `() =>`    | `formula: "() => context.item.qty * context.item.price"`     |
| Render custom HTML in a cell                     | `() =>`    | `render: "() => '<b>' + context.value + '</b>'"`             |
| Set default value from source type               | `() =>`    | `entityFactory: { sourceType: "() => context.source.type" }` |
| Conditionally style a cell                       | expression | `expression: "context.item.Risk > 50"`                       |
| Filter by today's date                           | `() =>`    | `">": "() => new Date().toISOString()"`                      |
| Show linked entity property                      | `() =>`    | `display: "() => context.document.title"`                    |

***

## Complete Sheet Configuration Example

The following example demonstrates multiple dynamic value expression types in a single sheet configuration:

```yaml theme={null}
sources:
  - id: requirements
    query:
      from: Requirement
      where:
        document:
          moduleName:
            "==": "() => context.document.moduleName"
        DueDate:
          ">": "() => new Date().toISOString()"
    entityFactory:
      sourceType: "() => context.source.type"

columns:
  title:
    title: Title
    hasFocus: true
  sourceType:
    title: Source Type
    isReadOnly: true
  quantity:
    title: Quantity
  unitPrice:
    title: Unit Price
  totalPrice:
    title: Total Price
    formula: "() => context.item.quantity * context.item.unitPrice"
    isReadOnly: true
  systemRequirement.document:
    display: "() => context.document.title"

renderers:
  linkedItems: "() => context.value.map((item) => `<b>${item.name}</b>`).join(', ')"

formatters:
  criticalHighlight:
    expression: "context.item.Probability <= 99"
    style: warningStyle
```

This configuration:

1. **Filters** the `Requirement` source by the current document's module name and future due dates
2. **Pre-fills** the `sourceType` field on new entities from the parent/source entity's work item type
3. **Calculates** `totalPrice` from `quantity` and `unitPrice` (persisted)
4. **Displays** the document title instead of a raw reference
5. **Renders** linked items with bold formatting
6. **Highlights** rows where `Probability` is 99 or below

***

## See Also

* [Constraints](/powersheet/reference/data-model/constraints) -- full reference on constraint configuration including stages, operators, and composition
* [Columns](/powersheet/reference/sheet-config/columns) -- column configuration properties including `formula`, `render`, and `display`
* [Formatters](/powersheet/reference/sheet-config/formatters) -- conditional formatting and style definitions
* [Sources](/powersheet/reference/sheet-config/sources) -- source query configuration including `where` and `entityFactory`
* [Binding Syntax](/powersheet/reference/sheet-config/binding-syntax) -- dot-notation paths for column keys
* [Navigation Directions](/powersheet/reference/data-model/navigation-directions) -- direct and back relationship directions
* [Cardinality](/powersheet/reference/data-model/cardinality) -- how relationship cardinality affects expand patterns and column binding

<LastReviewed date="2026-07-02" />
