Skip to main content

Document Context

VariableTypeDescription
$documentcom.nextedy.risksheet.model.DocumentThe RISKSHEET document object with access to custom fields and metadata
$!document.customFieldsMap<String, Object>Document’s custom fields from the Polarion LiveDoc. Access via $!document.customFields.fieldName
$!document.customFields.itemStringDocument custom field: item identifier
$!document.customFields.ownerStringDocument custom field: document owner
$!document.customFields.versionStringDocument custom field: document version
$!document.customFields.modelStringDocument custom field: model identifier
$!document.customFields.teamStringDocument custom field: assigned team
$!document.updatedjava.util.DateDocument’s last update timestamp
$doccom.nextedy.risksheet.polarion.RisksheetPolarionServiceImpl.wrapDocument()Wrapped document object providing enhanced Polarion integration
documentIdStringDocument identifier in format spaceId/documentId
projectIdStringPolarion project identifier

Transaction and Service Context

VariableTypeDescription
$txcom.polarion.alm.shared.api.transaction.ReadOnlyTransactionCurrent read-only transaction for accessing Polarion data
$transactioncom.polarion.alm.shared.api.transaction.ReadOnlyTransactionAlias for $tx
$trackerServiceITrackerServicePolarion work item and project management service
$securityServiceISecurityServicePolarion security and permissions service
$txServiceITransactionServiceTransaction management service
$repositoryServiceIRepositoryServiceFile repository and document access service

Utility Objects

VariableTypeDescription
$gsoncom.google.gson.GsonJSON serialization/deserialization utility
$objectFactoryObjectFactoryFactory for creating Polarion domain objects
$escEscapeToolHTML/XML/JavaScript escaping utility
$currentDatejava.util.DateCurrent system date and time
$calendarjava.util.CalendarCalendar instance for date manipulation

Accessing Document Custom Fields

<div class="row">
  <div class="rs-label">Item:</div>
  <div class="rs-value">$!document.customFields.item</div>
  <div class="rs-label">Owner:</div>
  <div class="rs-value">$!document.customFields.owner</div>
  <div class="rs-label">Version:</div>
  <div class="rs-value">$!document.customFields.version</div>
</div>

Working with Polarion Services

Accessing Work Items

#set($workItem = $trackerService.getWorkItem($projectId, 'FEAT-123'))
#if($workItem)
  <p>Title: $workItem.getTitle()</p>
  <p>Type: $workItem.getType().getId()</p>
#end

Loading External Configuration Files

#set($config = $repositoryService.getResource($projectId, 'path/to/config.xml'))
#if($config)
  #set($configJson = $gson.fromJson($config.getContent(), 'com.google.gson.JsonObject'))
  #set($riskMatrix = $configJson.get('riskMatrix'))
#end

Parsing XML Configuration

#set($xmlFile = $repositoryService.getResource($projectId, 'matrix/avasis-risks.xml'))
#if($xmlFile)
  #set($content = $xmlFile.getContent())
  ## Parse XML using Polarion's DOM utilities
  #set($doc = $objectFactory.parseXml($content))
  #foreach($item in $doc.getElementsByTagName('risk'))
    <div>$item.getAttribute('id'): $item.getTextContent()</div>
  #end
#end

Context Availability by Template Type

TemplateDocumentServicesTransactionCustom Fields
Top Panel
PDF Export
Custom Renderer
Configuration

Common Patterns

Conditional Display Based on Document Field

#if($document.customFields.projectType == 'medical')
  <div class="compliance-notice">FDA Compliance Required</div>
#end

Dynamically Load Risk Matrix

#set($matrixFile = "matrix-" + $document.customFields.model + ".json")
#set($resource = $repositoryService.getResource($projectId, "configs/$matrixFile"))
#if($resource)
  #set($matrix = $gson.fromJson($resource.getContent(), 'java.util.Map'))
#end

Access Nested Work Item Properties

#set($parent = $trackerService.getWorkItem($projectId, $document.customFields.parentItem))
#if($parent)
  <p>Parent: $parent.getTitle()</p>
  <p>Status: $parent.getStatus().getId()</p>
  #set($children = $parent.getLinkedItems('child'))
  #foreach($child in $children)
    <li>$child.getId()</li>
  #end
#end
Use the $! silent reference syntax (with !) to avoid displaying null values. Always check for null results from service calls before accessing properties. Cache frequently-accessed data in template variables using #set() to improve performance.
Avoid excessive repository or service calls within loops. Each call incurs transaction overhead. Load shared configuration files once and cache the results. Consider using Polarion batch APIs for querying multiple work items.
The velocity context respects Polarion’s security model. Users can only access work items and documents they have permission to view. The transaction is read-only, preventing unintended modifications.

Error Handling

#try
  #set($item = $trackerService.getWorkItem($projectId, $itemId))
  #if($item)
    Display item content
  #else
    <p class="error">Work item not found</p>
  #end
#catch($e)
  <p class="error">Error loading work item: $e.message</p>
#end

Escaping Output

When rendering user-supplied data or external content, use the escape utility to prevent XSS vulnerabilities:
#set($title = $document.customFields.title)
<p>$esc.html($title)</p>
<script>var json = '$esc.javascript($jsonData)';</script>

Integration with Multi-Project Setups

For configurations spanning multiple projects, use document custom fields to reference centralized resources:
#set($centralProject = $document.customFields.configProject)
#set($matrixResource = $repositoryService.getResource($centralProject, 'shared/risk-matrix.json'))
#if($matrixResource)
  #set($matrix = $gson.fromJson($matrixResource.getContent(), 'java.util.Map'))
#end
KB ArticlesSupport TicketsSource Code
  • RisksheetViewServlet.java
  • AppConfig.ts
  • PdfExportConfigurationService.java
  • AppConfigParser.ts