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.
Template Structure
A typicalrisksheetTopPanel.vm file contains three sections:
| Section | Purpose | Example |
|---|---|---|
<style> block | CSS rules for panel layout, image sizing, and custom classes | .rs-top-panel-info { padding: 8px; } |
| HTML markup | Document metadata display, action buttons, filter controls | <div>Product: $!productFamily</div> |
<script> block | JavaScript functions for formulas, query factories, and context menu actions | function calcRisk(info) { ... } |
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.| Variable | Type | Description |
|---|---|---|
$doc | IModule | Current Polarion document object. Provides access to document metadata, custom fields, and the module API |
$document | Document | Risksheet document wrapper with customFields access for direct field reading |
$transaction | ITransaction | Current Polarion transaction for data operations |
$trackerService | ITrackerService | Polarion tracker service for work item queries and data retrieval |
$projectService | IProjectService | Polarion project service for project-level metadata |
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:
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 thatrisksheet.json 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:
risksheet.json:
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 eachrisksheet.json:
riskCondition formulas in each project’s risksheet.json 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):
risksheet.json:
Enum Type Identifiers
When configuring enum columns, thetype property in risksheet.json 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 risksheet.json 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.
| Property | Type | Description |
|---|---|---|
label | string | Text displayed in the context menu |
enabled | function(item) | Returns true if the action is available for the given item. The function receives the current row’s data object |
execute | function(item) | The action to perform when clicked. The function receives the current row’s data 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, risk evaluation function, query factory, and custom context menu action:
risksheet.json formulas reference the top panel functions:
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