Skip to main content

How Page Scripts Work

Page scripts run on the Polarion server using the Apache Velocity template engine. The rendered output is then embedded into the Gantt widget as JavaScript. This means you can use Velocity expressions to access Polarion data (projects, users, plans, work items) and inject dynamic values into the Gantt configuration. diagram

Available Velocity Context Variables

The following objects are available inside page scripts:
VariableTypePurpose
$projectPolarion projectCurrent project reference
$userPolarion userCurrent logged-in user
$trackerServicePolarion serviceQuery work items and plans
$pageWiki pageCurrent page reference
configGantt configWidget configuration object
markerFactoryMarker factoryCreate timeline markers

Create a Baseline Comparison Page

This example creates a portal page that lists project baselines and opens the Gantt chart with a comparison overlay.
  1. Add a page parameter named baselineRevision of type string to your Gantt report page.
  2. In Widget Parameters > Advanced > Item Script, add the baseline loading logic:
    var revision = config.getPageParameters().get("baselineRevision");
    if(revision && revision.length > 0){
        var origWi = wi.getDataSvc().getVersionedInstance(wi.uri, revision);
        task.planned_start_date = util.getDate(origWi, "start");
        task.planned_duration = util.getDuration(origWi, "initialEstimate");
    }
    
  3. Create a separate Wiki page with this Velocity snippet to list baselines:
    #set($projectId = $page.reference.projectId)
    #set($ganttPagePath = "/project/$projectId/wiki/Planning/Gantt")
    #set($project = $trackerService.getTrackerProject($projectId))
    <ul>
    #foreach($b in $project.baselinesManager.baselines)
        <li>
            <a target="_blank"
               href="/gantt/polarion/#$ganttPagePath?baselineRevision=$b.getBaseRevision()">
                <b>$b.name</b> - $b.getBaseRevision()
            &lt;/a&gt;
            &lt;br/&gt;$b.baseRevisionObject.created
        &lt;/li&gt;
    #end
    &lt;/ul&gt;
    
The field names in util.getDate(origWi, "start") and util.getDuration(origWi, "initialEstimate") must match the field names in your widget Data Mapping section. If you use plannedStart and duration, update the script accordingly.

Add Dynamic Markers with Velocity

Use the markerFactory in the Markers Script to create timeline markers from Polarion data. For example, load iteration boundaries from plans:
markerFactory.addPlanMarkers(
    "template.id:iteration AND project.id:" + config.getContextProjectId(),
    "blue"
)
Or load project time points using the Polarion API:
var timePoints = trackerService.getTrackerProject("$projectId")
    .getTimePoints().iterator();
while(timePoints.hasNext()){
    var tp = timePoints.next();
    var marker = markerFactory.addMarker();
    marker.setText(tp.getName());
    marker.setDate(tp.getTime().getDate());
    marker.setColor("fuchsia");
}
If you are on Polarion 2304 or later, use getter methods like tp.getName() and tp.getTime().getDate() instead of direct property access like tp.name and tp.time.date. See Migrate Scripts for Polarion 2304+ for details.

Verify Your Changes

After saving the page, reload the Gantt chart. You should now see:
  • Baseline comparison bars rendered below current task bars (if a baseline revision is selected)
  • Dynamic markers appearing as vertical lines on the Gantt timeline
  • Velocity-generated values correctly resolved in the widget output

See Also

KB ArticlesSource Code
  • prod-gantt-src/com.nextedy.polarion.gantt/src/com/nextedy/polarion/gantt/model/impl/GanttScriptTransformer.java
  • prod-gantt-src/com.nextedy.polarion.gantt/src/com/nextedy/polarion/gantt/model/MarkerFactory.java
  • prod-gantt-src/com.nextedy.polarion.gantt/src/com/nextedy/polarion/gantt/model/impl/PlannedInFieldFilter.java
  • prod-gantt-src/com.nextedy.polarion.gantt/src/META-INF/hivemodule.xml