Skip to main content

Template File and Loading

The template file is named risksheetTopPanel.vm and is stored as a document attachment in Polarion. The /api/panel endpoint loads the file, renders it through the Velocity engine with full access to Polarion services, and returns the resulting HTML. If an error occurs during rendering, a red error message box displays instead of the panel content.
diagram
If no risksheetTopPanel.vm file is attached to the current document, Risksheet searches the document’s template hierarchy. The system uses the same configuration inheritance path as the sheet configuration. See Template Path Configuration for the lookup order.

Three-File Architecture: Declarative Config vs Custom Logic

Risksheet uses three distinct configuration files, each with a different role and change-management profile. Understanding this separation is critical for regulated industries (medical devices, automotive, aerospace):

Why Externalize JavaScript to the Top Panel?

This separation simplifies change management in regulated industries:
  1. Validation scope — When the risk matrix changes (for example, severity thresholds updated), only the top panel changes. The sheet configuration (which defines grid structure) is untouched, narrowing the validation scope for change control.
  2. Auditability — The sheet configuration is a declarative artifact. Tools can automatically verify its structure (correct property names, valid enum references, level consistency) without parsing JavaScript.
  3. Template reuse — The same sheet configuration structure can work with different calculation strategies by swapping the top panel. For example, one top panel implements a 2D risk matrix (severity x occurrence to classification); another implements a 3D RPN calculation (S x O x D to numeric score).
  4. Separation of concerns — Configuration authors (risk managers) define WHAT columns exist and how data flows. Script authors (developers, validation engineers) define HOW values are calculated. Different competencies, different review gates.
Recommended pattern: in the sheet configuration, keep formulas entries as thin wrappers that delegate to functions defined in the top panel. Example:
The full getInitialRE implementation lives in the top panel <script> block, alongside risk matrix logic and any jQuery-based cell decorators. In-line formulas in the sheet configuration are acceptable for simple calculations (for example, RPN = S * O * D); complex logic (risk matrices, multi-field conditional formatting) should be externalized to the top panel.

Template Structure

A typical risksheetTopPanel.vm file contains three sections:

Velocity Context Variables

The top panel template receives the full Velocity context with access to Polarion services and document data. See Velocity Template Context for the complete reference.

$securityService — Role-Based UI

The $securityService is available in top panel Velocity and exposes the current user and that user’s roles. Use it to drive role-based default views, conditional rendering, and permission-aware UI:
Typical use cases: showing reviewer-only filters, hiding administrative buttons from end users, and selecting an appropriate saved view per role.

Accessing Document Custom Fields

There are two approaches to reading document-level custom fields in the top panel.

Method 1: $doc.getOldApi().getValue()

Use $doc.getOldApi().getValue('customFieldID') for programmatic access. This is the preferred method when you need to pass values into JavaScript variables:

Method 2: $document.customFields

Use $document.customFields.fieldName for direct display in HTML markup:
$!document.customFields.<field> renders the document custom-field value correctly in the top panel template — the shipped Risksheet top panels rely on it (for example $!document.customFields.item, owner, version, model, team). This differs from a standard Polarion page Velocity context, where $document.customFields may print empty and $document.getValue('id') is the usual form. In the top panel, both Method 1 and Method 2 above are valid; use $! (with the exclamation mark) to suppress null-reference output for optional fields.
The top panel can display document custom fields but cannot modify them. To change document field values, use the standard Polarion document editor. Custom context menu actions for document workflow transitions are not natively supported.
Table-type custom fields can also be accessed via $doc.getOldApi().getValue('customFieldID'). The returned object structure depends on the Polarion table field implementation.

Bridging Server Data to Client-Side Formulas

The primary use case for the top panel template is defining JavaScript functions that sheet configuration formulas can call. This bridges server-side Polarion data (accessible via Velocity) into client-side formula execution.

Pattern

diagram
Step 1. Define a JavaScript function in risksheetTopPanel.vm using Velocity to inject server-side data:
Step 2. Reference the top panel function from a formula in the sheet configuration:
Top panel functions called from formulas receive the same info object. Access work item field values via info.item['fieldId'] and return the result. Prepare all needed values within functions defined in the top panel file.

Reading Downstream Task Data with risksheet.ds.getDownstreamRows

For formulas that need access to downstream task work items linked from the current risk row, the client-side data source exposes risksheet.ds.getDownstreamRows(riskId). This is useful for aggregating values across mitigation tasks, computing initial-vs-residual risk indices, or iterating over multi-round assessments.
This API enables risk roll-ups and cross-row aggregations that would otherwise require server-side rendering or custom Velocity macros.

Dynamic Risk Matrices from External Sources

The top panel can reference external data sources via Velocity context and Polarion APIs, enabling dynamic risk matrix definitions shared across projects without duplicating formula logic in each sheet configuration:
This pattern replaces hardcoded riskCondition formulas in each project’s sheet configuration with a centralized, dynamic matrix definition.
The exact API for loading attachments and external XML files depends on your Polarion version and installed plugins. The pattern above demonstrates the general approach — verify the specific Polarion API calls in your environment.

Filtering Linked Items with Query Factory

Combine the top panel template with a query factory function to filter item suggestions based on document-level fields. This is useful when different documents in the same project should only link to items matching their product family or variant. Top panel template (risksheetTopPanel.vm):
Column configuration in the sheet configuration:
The query factory function constructs a Lucene query string that filters the item suggester results. The function receives a single info object describing the current row and context.

Enum Type Identifiers

When configuring enum columns, the type property in the sheet configuration must match the enum definition name in Polarion’s custom fields XML. The top panel can help verify or map enum identifiers:
Check the .polarion/documents/fields/custom-fields.xml file in your project’s SVN repository for the exact enum definition name to use in the type property. The enum type identifier in the sheet configuration must match exactly.

CSS Styling in the Top Panel

The top panel template can include <style> blocks to control the appearance of the panel content, rich text images, and custom cell rendering:
When rendering rich text fields with images via server render columns, set the bindings to task.$item rather than the specific field binding. Control image sizing through CSS in the top panel. See Render Custom Data for details.

Context Menu Integration

Custom context menu actions can be registered via window.risksheet.customContextMenuActions in the top panel <script> block. Functions must exist on the global window object.
Each custom context menu action requires three properties:

Maximize/Restore Toggle

The top panel visibility can be toggled by the user to maximize the grid viewing area. When toggled:
  • The top panel hides entirely
  • The grid expands to use the full available space
  • The toggle button is always available in the toolbar
This is useful when the top panel displays informational content that is not needed during active editing.

Error Handling

If the risksheetTopPanel.vm template contains errors (Velocity syntax errors, missing variable references, or JavaScript errors), the panel displays a red error message box instead of the expected content. The grid remains functional even when the top panel fails to render.
If the top panel displays an error, check the Polarion server logs for Velocity rendering errors. Common issues include missing $doc references, undefined custom field IDs, and malformed Velocity syntax. Use $!variable (with exclamation mark) to suppress null reference errors for optional fields.

Complete Example

A full risksheetTopPanel.vm file for an FMEA document with metadata display, role-aware default view, risk evaluation function, downstream task aggregation, query factory, and a custom context menu action:
The corresponding sheet configuration formulas reference the top panel functions:
Last modified on July 10, 2026