Skip to main content
This page has limited source coverage. Variable availability and behavior should be verified against your Polarion version.

Velocity Pre-processing Flow

diagram Velocity expressions use the $variable syntax. The Velocity engine replaces these with actual values from the Polarion server context before any script logic runs.

Available Context Variables

VariableTypeDescription
$projectIProjectThe current Polarion project context. Access project metadata, configuration, and related objects.
$userIUserThe currently authenticated Polarion user. Access user ID, name, roles, and preferences.
$trackerServiceITrackerServicePolarion tracker service for querying work items, projects, and time points via Lucene queries.
Additional Velocity context variables may be registered by Polarion extensions. The variables listed above are confirmed from the Gantt extension configuration. Check your Polarion instance for the complete set of available Velocity context objects.

Usage in Item Script

Velocity expressions in the Item Script are resolved on the server before the script executes per work item. Use Velocity to inject server-side data into your script logic:
// Velocity resolves $project.id before script execution
var currentProject = "$project.id";

if (wi.getType().getId() === "feature") {
    task.getFields().put("projectName", "$project.name");
}

Usage in Gantt Config Script

Velocity expressions in the Gantt Config Script are resolved on the server before the script is sent to the client browser:
// Server resolves $user.id, client receives the actual user ID string
var currentUser = "$user.id";

gantt.templates.rightside_text = function(start, end, task) {
    if (task.fields.owner === currentUser) {
        return "<b>Assigned to you</b>";
    }
    return "";
};

Usage in Markers Script

Velocity expressions in the Markers Script are resolved before marker creation logic runs:
// Dynamic project reference via Velocity
var timePoints = trackerService.getTrackerProject("$project.id").getTimePoints().iterator();
while (timePoints.hasNext()) {
    var tp = timePoints.next();
    var marker = markerFactory.addMarker();
    marker.setText(tp.getName());
    marker.setDate(tp.getTime().getDate());
    marker.setColor("blue");
}

Common Patterns

Dynamic Project ID

Avoid hardcoding project IDs by using Velocity:
// Instead of: "project.id:MyProject"
var query = "project.id:$project.id AND type:release";
var releases = trackerService.queryWorkItems(query, "id").iterator();

User-Specific Behavior

Customize Gantt behavior based on the current user:
var userId = "$user.id";
if (wi.getAssignees() != null) {
    var aIterator = wi.getAssignees().iterator();
    while (aIterator.hasNext()) {
        var assignee = aIterator.next();
        if (assignee.getId() === userId) {
            task.taskColor = "#a9d08e";
        }
    }
}

Conditional Script Sections

Use Velocity directives to include or exclude entire script blocks:
#if($project.id == "CriticalProject")
gantt.config.drag_links = false;
gantt.config.drag_progress = false;
#end
Velocity expressions ($variable, #if, #foreach) are processed on the server and produce plain text output. JavaScript logic (if, for, var) executes afterward. Do not confuse the two — Velocity runs first and generates the JavaScript that will run.

Escaping

The Velocity-resolved script output is escaped for safe embedding in the page. Backslashes, single quotes, and newlines are automatically handled. You do not need to manually escape these characters in your Velocity expressions.

Configuration Example

A complete Item Script combining Velocity context with JavaScript logic:
// Velocity injects the current project and user
var projectId = "$project.id";
var currentUser = "$user.id";

if (wi != null) {
    // Highlight tasks assigned to the current user
    var aIterator = wi.getAssignees().iterator();
    while (aIterator.hasNext()) {
        var assignee = aIterator.next();
        if (assignee.getId() === currentUser) {
            task.taskColor = "#a9d08e";
            task.getFields().put("myTask", "true");
        }
    }

    // Set project-specific defaults
    task.getFields().put("sourceProject", projectId);
}
Source Code
  • prod-gantt-src/com.nextedy.polarion.gantt/src/META-INF/hivemodule.xml
  • prod-gantt-src/com.nextedy.polarion.gantt/src/com/nextedy/polarion/gantt/model/impl/GanttScriptTransformer.java