Skip to main content

Template Evaluation

diagram

Context Variables

The following variables are available in every Velocity template evaluation.
VariableTypeDescription
$itemModelObjectPrimary work item accessor. Provides access to all work item properties and methods.
$wiIWorkItemLegacy Polarion work item API. Only available for work item entities. Use for methods not available on $item.
$txTransactionCurrent transaction object for transactional queries and read-only operations.
$moduleIModuleDocument (LiveDoc) containing the work item. null for entities not within a document.
$contextPowersheetContextPowersheet-specific context providing access to project scope, document scope, and query capabilities.
See Context Variables for detailed documentation on each variable.

Platform Services

Platform services are cached and pre-injected into every template evaluation.
VariableServicePurpose
$trackerServiceITrackerServiceQuery work items, access project metadata, run Lucene searches
$txServiceITransactionServiceTransaction management within templates
$repositoryServiceIRepositoryServiceAccess project metadata, users, roles, repository configuration
$securityServiceISecurityServiceCheck permissions, implement role-based visibility
See Polarion Services for detailed service documentation.

Template Syntax

Velocity templates use standard Apache Velocity syntax.

Variable References

$item.title
$item.status.id
$wi.getLinkedWorkItems()

Conditional Logic

#if($item.status.id == "approved")
  Approved
#else
  Pending
#end

Method Calls

$trackerService.getWorkItemByUri($item.uri)
$securityService.getCurrentUser().getId()
The exact methods available on each service depend on the Polarion server version. Consult the Polarion API documentation for your version.

Error Handling

Error TypeBehavior
Parse errorReturns #SERVER_RENDER_ERROR constant
Method invocation errorReturns #SERVER_RENDER_ERROR constant
Resource not foundReturns #SERVER_RENDER_ERROR constant
When a Velocity template fails to evaluate, the cell displays #SERVER_RENDER_ERROR. Check the Polarion server logs for the specific error details (parse errors, method invocation errors, or missing resources).

Template Performance

AspectDetail
Service context cachingPlatform services ($trackerService, etc.) are cached in a static context and reused across all template evaluations
Per-item context$item, $wi, $module, and $context are set per work item evaluation
Evaluation scopeTemplates execute once per work item per query
Server-rendered templates execute for every work item returned by a query. Avoid expensive operations (e.g., complex Lucene queries within templates) that multiply across large result sets.

Server-Rendered Property Configuration

Server-rendered properties are defined in the domain model using the serverRender annotation. When a property has serverRender configured, it becomes read-only (not updatable) regardless of other permission settings.
PropertyTypeDefaultDescription
serverRenderstringnullVelocity template pattern to evaluate. When set, property is automatically marked read-only.
readablebooleantrueWhether the property is visible to clients
updatablebooleanfalse (when serverRender is set)Automatically set to false for server-rendered properties

Test Context Validation

The server renderer validates that the Velocity context contains the required variables:
Required VariableType
itemModelObject (work item)
txTransaction
contextPowersheetContext
pObjectIPObject (raw Polarion object)

Document Parameters in Templates

Document parameters can be used within Velocity templates via the $context variable:
$context.parameters.model
$context.document.id
See JavaScript Functions for client-side $context expressions.

Complete YAML Example

Domain model with a server-rendered property:
domainModelTypes:
  SystemRequirement:
    polarionType: systemRequirement
    properties:
      title: ~
      severity: ~
      computedStatus:
        serverRender: |
          #if($item.status.id == "approved")Approved#else$item.status.id#end
Sheet configuration referencing the computed property:
columns:
  id:
    width: 80
  title:
    width: 300
    hasFocus: true
  computedStatus:
    width: 120
    formatter: readOnly

sources:
  - id: requirements
    title: System Requirements
    model: rtm
    query:
      from: SystemRequirement
      where: "<WHERE>"

Source context: ServerRenderer, ServerRendererTest, QueryDataTest, Property, document parameter fixtures
Source Code
  • ServerRenderer.java
  • MetadataTest.java
  • QueryDataTest.java
  • Property.java
  • ServerRendererTest.java