Skip to main content

What Item Scripts Do

Item scripts run on the server for each work item loaded into the Gantt chart. They let you read data from the Polarion work item object (wi) and pass it to the client-side task object (task) using the task.getFields().put(KEY, VALUE) pattern. Common use cases include extracting assignee names, computing custom labels, reading custom field values, and controlling task visibility.

Access the Item Script Parameter

  1. Open your Gantt page in Edit mode.
  2. In the widget parameter sidebar, expand the Advanced section.
  3. Locate the Item Script text area.
  4. Enter your JavaScript snippet.
  5. Click Apply.

Available Variables

Item scripts have access to the following server-side variables:
VariableTypeDescription
taskTaskThe Gantt task object being sent to the client
wiIWorkItemThe Polarion work item (read data from here)
itemIWorkItemAlias for wi
planIPlanThe Polarion plan (Plans Gantt only)
configConfigThe current Gantt configuration object
ganttDataServiceIGanttDataServiceServer-side data service for advanced queries
utilUtilityHelper methods (e.g., getDate, getDuration)
Additionally, Velocity pre-processing runs before script execution, making $project and $user available as Velocity expressions within the script text.

Task Object Properties

The task object contains the following fields that you can read or modify:
FieldTypeDescription
idStringUnique task identifier
textStringDisplay label (work item ID + title)
start_dateDateTask start date
durationintTask duration in days (default: 10)
progressfloatCompletion percentage (0.0 to 1.0)
parentStringParent task ID
typeStringTask type (task, project, milestone)
urlStringLink to the Polarion work item
itemIdStringPolarion work item ID (e.g., “WI-123”)
projectIdStringPolarion project ID
readonlybooleanWhether the task is read-only
unplannedbooleanWhether the task has no scheduled dates
openbooleanWhether the task node is expanded
colorStringCSS color for the task bar
fieldsMapCustom key-value pairs passed to the client

Basic Example: Pass Assignee Names to the Client

if (wi.getType().getId() === 'task') {
    var aIt = wi.getAssignees().iterator();
    var assignees = "";
    var separator = "";
    while (aIt.hasNext()) {
        var assignee = aIt.next();
        assignees = assignees + separator + assignee.name;
        separator = ", ";
    }
    if (assignees !== "") {
        task.getFields().put("assignees", assignees);
    }
}
This script reads all assignees from the work item and stores a comma-separated string in the fields map under the key "assignees". You can then reference this value in Gantt Config Script templates (for example, to display it as right-side text on the task bar).

Control Task Visibility

Use the task.hide property to hide specific work items from the chart:
if (wi.getType().getId() === 'changeRequest') {
    task.hide = true;
}
Use task.hide in item scripts when you need conditional logic beyond what the widget query provides. For simple type filtering, configure the query directly in the widget parameters instead.

Error Handling

Script errors are logged on the server but do not crash the Gantt chart load. When an item script contains an error, a warning indicator appears in the Gantt toolbar showing the error count. Hover over it to see the error details.
If you upgraded to Polarion 2304 or later, existing item scripts may stop working. Key changes:
  • Use typeof wi !== 'undefined' instead of wi != null for null checks.
  • Use getter methods instead of direct property access: wi.getStatus().getId() instead of wi.status.id.
  • Use wi.getType().getId() instead of wi.type.id.
See Migrate Scripts for Polarion 2304+ for a full migration guide.

Verification

After adding an item script, you should now see:
  • No error indicator in the Gantt toolbar (the script runs without errors).
  • Custom field values available in the task data (verify by referencing them in a Gantt Config Script template or tooltip).
  • Tasks hidden or modified according to your script logic.

See Also

KB ArticlesSupport TicketsSource Code
  • prod-gantt-src/com.nextedy.polarion.gantt.client/cypress/e2e/ganttCheckWarningInfo.cy.ts
  • prod-gantt-src/com.nextedy.polarion.gantt/src/com/nextedy/polarion/gantt/model/impl/ScriptEvaluator.java
  • prod-gantt-src/com.nextedy.polarion.gantt.client/src/js/nextedy.js
  • 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/impl/AbstractBaseGanttDataService.java