Template File and Loading
The template file is namedrisksheetTopPanel.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.
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:- 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.
- 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.
- 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).
- 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.
formulas entries as thin wrappers that delegate to functions defined in the top panel. Example:
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 typicalrisksheetTopPanel.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:
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.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
risksheetTopPanel.vm using Velocity to inject server-side data:
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 exposesrisksheet.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: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):
info object describing the current row and context.
Enum Type Identifiers
When configuring enum columns, thetype 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:
Context Menu Integration
Custom context menu actions can be registered viawindow.risksheet.customContextMenuActions in the top panel <script> block. Functions must exist on the global window object.
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
Error Handling
If therisksheetTopPanel.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.
Complete Example
A fullrisksheetTopPanel.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:
Related Pages
- Velocity Template Context — full list of available Velocity context variables
- Velocity Templates — Velocity template engine reference and syntax
- Custom Renderer Templates — cell display customization templates
- PDF Export Template — PDF export Velocity template
- Formula Functions — formula patterns that call top panel functions
- Customize the Top Panel — step-by-step how-to guide
- Configuration Properties Index — all configuration properties