Skip to main content
diagram

Template Files

FilePurposeEndpointRequired
risksheetTopPanel.vmRenders customizable HTML panel above the Risksheet grid/api/panelNo
risksheetPdfExport.vmGenerates JavaScript export script for PDF generation/api/pdfscriptNo
risksheet.jsonPrimary configuration file (supports Velocity expressions in values)/api/configYes

Template Resolution Properties

Templates are loaded from document attachments with fallback to the template hierarchy. The resolution mechanism tracks where the configuration was found using these properties:
PropertyTypeDefaultDescription
configstringFile name (e.g., risksheet.json)Name of the configuration file attachment to load from the Polarion document. If not found on the document, the system searches the document’s template hierarchy.
fromTemplatebooleanfalseFlag indicating whether the configuration was loaded from a template document rather than the target document itself. Set to true when configuration is inherited from a template module.
configPathstringNoneURI path to the configuration attachment that was actually loaded, whether from the document itself or from a template. Used for debugging and configuration source tracking.
templateNamestringNoneDisplay name of the template document from which configuration was inherited. Includes project name prefix if template is from a different project. Empty if configuration is directly attached to the document.
fileNamestringNonePath and name of the document where configuration was requested (not necessarily where it was found). Formatted as folder/documentTitle.
revisionstringNoneData revision identifier of the cached configuration attachment. Used to invalidate cache when attachment content changes.
diagram
Define templates once at the template document level. All documents created from that template inherit the Velocity templates automatically. Override individual templates by attaching a file with the same name directly to a specific document.

Velocity Context Variables

All Risksheet Velocity templates receive a context containing Polarion services, document objects, and utility tools. The available context variables depend on the template type.

Common Context (All Templates)

VariableTypeDescription
$document / $docPolarion Module objectCurrent Polarion document (module) with access to metadata, custom fields, and work items
$repositoryServicePolarion serviceAccess to Polarion repository operations for querying projects, documents, and work items
$transactionPolarion transactionCurrent database transaction for read/write operations within the template
Velocity ToolsUtility objectsStandard Velocity utility tools for formatting, math, and string operations

Top Panel Template Context (risksheetTopPanel.vm)

The top panel template renders at the /api/panel endpoint and has full access to the common Velocity context plus:
Additional ContextDescription
Document custom fieldsAccess via $doc.getOldApi().getValue("fieldId")
Project configurationAvailable through $repositoryService
Polarion tracker servicesQuery work items and links from within the template
Errors in the top panel template render as a red error message box in place of the panel content, displaying the exception details.

PDF Export Template Context (risksheetPdfExport.vm)

The PDF export template renders at the /api/pdfscript endpoint and includes additional context:
Additional ContextTypeDescription
pdfExportMacros.vmVelocity macrosHelper macros for PDF-specific formatting and layout operations
revision parameterstringRequired document revision identifier for the export. Must be specified in the request.
See PDF Export Template for detailed template structure and macro reference.

Velocity Syntax Reference

Variables and Properties

## Access a simple variable
$variableName

## Access a nested property
$document.customFields.productFamily

## Access via method call (required for some Polarion APIs)
$doc.getOldApi().getValue("customFieldID")

## Quiet reference (no output if variable is null)
$!{variableName}

Directives

## Set a variable
#set($myVar = "value")

## Conditional rendering
#if($condition)
  content when true
#elseif($otherCondition)
  alternative content
#else
  default content
#end

## Iteration over a collection
#foreach($item in $collection)
  $item.name ($velocityCount of $collection.size())
#end

## Include another template
#parse("included-template.vm")

Embedding JavaScript in Velocity

A key pattern in Risksheet templates is bridging server-side Polarion data to client-side JavaScript logic. The Velocity template executes on the server and generates HTML/JavaScript that runs in the browser:
## Extract document-level custom field on the server
#set($productFamily = $doc.getOldApi().getValue("productFamily"))
#set($projectId = $document.projectId)

<script>
  // Server-rendered values become client-side JavaScript variables
  var productFamily = "$productFamily";
  var projectId = "$projectId";

  // Define a queryFactory function that uses server-side data
  function filterByProductFamily(item) {
    return "customFields.productFamily:" + productFamily;
  }
</script>
When embedding Velocity variables into JavaScript strings, ensure the variable values do not contain characters that would break JavaScript syntax (quotes, backslashes, newlines). Use $esc.javascript($value) if the Velocity EscapeTool is available, or validate that custom field values contain only safe characters.

PDF Export Configuration Properties

The PDF export configuration service manages loading of the risksheetPdfExport.vm template:
PropertyTypeDefaultDescription
risksheetPdfExport.vmstringrisksheetPdfExport.vmName of the Velocity template file containing PDF export configuration. Attached to Polarion documents to customize PDF export behavior per document or project.
pdfExportConfigurationstringNoneThe full content of the PDF export Velocity template as a string. Contains the script/configuration that controls how Risksheet data is exported to PDF format.
templateNamestringNoneName of the template used for PDF export configuration. Set when the configuration is loaded from a template.
fromTemplatebooleanfalseFlag indicating whether the PDF export configuration was loaded from a template rather than directly from a document attachment.
configPathstringNoneFile system or repository path to the configuration file. Indicates where the PDF export configuration Velocity template is stored.
fileNamestringNoneName of the configuration file. Used to track which file contains the PDF export configuration.

Project Template Installation

Risksheet ships with predefined project templates that can be installed via the administration interface:
Template IDDescriptionUse Case
risksheet_templateStandard Risksheet project templateGeneral FMEA risk analysis with default column layout and severity/occurrence/detection scales
risksheet_templateHaraHARA-specific project templateHazard Analysis and Risk Assessment (HARA) workflows per ISO 26262

Installation Properties

PropertyDescription
Installation endpointPOST /admin/setup
Duplicate detectionSystem automatically checks if risksheet_template is already installed before attempting installation
Overwrite behaviorRe-installing templates deletes existing template data first, then uploads fresh versions
Transaction safetyInstallation is wrapped in database transactions with automatic rollback on failure
Environment detectionAutomatically detects development vs. production environment and loads template files from appropriate locations
Multi-template supportTemplate ZIP files can contain multiple templates, each identified by a template.properties file in its directory root
Re-installing templates overwrites previous versions completely. The system removes old template data before uploading new versions to ensure a clean state. Back up any customizations made to installed templates before re-running setup.

Runtime Configuration Properties

When templates are loaded at runtime, the application exposes version and configuration metadata through the window context:
PropertyTypeSourceDescription
versionstringrisksheet.versionFull version string of the Risksheet application including build metadata
shortVersionstringrisksheet.shortVersionShortened version identifier without build metadata for display
baseUrlstringrisksheet.baseUrlBase URL for the Risksheet application, used to construct API endpoints
projectIdstringrisksheet.projectIdPolarion project identifier used in API endpoint construction
revisionstringrisksheet.revisionDocument revision identifier; empty string indicates head revision, non-empty forces read-only mode
currentRevisionstringrisksheet.currentRevisionLatest revision number of the document
canAdminbooleanrisksheet.canAdminWhether the current user has administrative privileges to modify configuration
configEditUrlstringConstructedURL to the Risksheet configuration editor: ${baseUrl}/risksheet/configuration/
documentUrlstringConstructedDirect URL to the source Polarion document in the standard Polarion UI
sourcestringConfigurationPath to configuration source file (document or template) used to load the current configuration
templateNamestringConfigurationName of the template when configuration is loaded from a global template rather than document-specific config

Error Handling

Error TypeTemplateBehavior
Velocity syntax errorTop panelError details rendered as red HTML message box in the panel area
Velocity syntax errorPDF exportExport fails with error message in the export output
Missing template variableAllEmpty string rendered (Velocity default quiet reference behavior)
Template file not foundTop panelDefault empty panel displayed
Template file not foundPDF exportExport uses default behavior or fails gracefully
Runtime exception (e.g., StringIndexOutOfBoundsException)AllRed error message box with exception details; typically caused by misconfigured template or risksheet.json
UnsupportedOperationException for renderingLayoutsAllNon-functional log error; fixed in Risksheet 24.7.0+
When a Velocity template error occurs, the error message is rendered directly in the panel or export output. Check the Polarion server logs for the full stack trace. Common causes include misconfigured risksheetTopPanel.vm files and references to document custom fields that do not exist.

Complete Example

A top panel template that extracts a document custom field and registers a queryFactory function for filtering linked items by product family:
## risksheetTopPanel.vm
## Extract document-level custom fields using Polarion API
#set($productFamily = $doc.getOldApi().getValue("productFamily"))
#set($riskOwner = $doc.getOldApi().getValue("riskOwner"))
#set($projectName = $document.projectId)

<div class="risksheet-top-panel" style="padding: 8px; background: #f5f5f5; border-bottom: 1px solid #ddd;">
  <span><strong>Product Family:</strong> $!{productFamily}</span>
  <span style="margin-left: 16px;"><strong>Risk Owner:</strong> $!{riskOwner}</span>
  <span style="margin-left: 16px;"><strong>Project:</strong> $projectName</span>
</div>

<script>
  // Bridge server-side document data to client-side queryFactory
  var _productFamily = "$!{productFamily}";

  // Register queryFactory for filtering linked items by product family
  window.risksheet = window.risksheet || {};
  window.risksheet.queryFactories = window.risksheet.queryFactories || {};
  window.risksheet.queryFactories["filterByFamily"] = function(item) {
    if (_productFamily) {
      return "customFields.productFamily:" + _productFamily;
    }
    return "";
  };
</script>
This pattern demonstrates:
  1. Accessing document custom fields with $doc.getOldApi().getValue()
  2. Rendering server-side data into HTML for display
  3. Passing server-side values to client-side JavaScript variables
  4. Registering a queryFactory function that uses document-level context to filter which items are available for linking in Risksheet columns

See Also

KB ArticlesSupport TicketsSource Code
  • PdfExportConfigurationService.java
  • AppConfig.ts
  • RisksheetViewServlet.java
  • AppConfigParser.ts
  • RisksheetSetupService.java