The Item Script widget parameter lets you prepare and enrich data on the server before it is sent to the client. You can use this data to customize what is rendered to the right of a task, in tooltips, and more — for example check How to change text on right?
In this article we dive deeper into the Item Script.
TABLE OF CONTENTS
Overview
This script runs server-side in JavaScript (not Velocity). The goal is not to render HTML, but to read data from the Polarion work item and pass it to the client as a serialized object.
Two variables are pre-defined for you:
First, this script is executed on the server and it is in "javascript" language. So you write a snippet in javascript, that is executed on the server, not on client. We use javascript rather than velocity, because the goal is not to render the data, but to prepare / massage the data.
| Variable | Type | Description |
| task | com.nextedy.polarion.gantt.model.Task | The Gantt task object you will populate |
| wi | com.polarion.alm.tracker.model.IWorkItem | The source Polarion work item |
The typical pattern is to read from wi and write to task using:
task.getFields().put(KEY, VALUE);
Example — passing assignees to the client
if (wi.getType().getId() === 'portfolioepic') {
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);
}
}Task class reference
public class Task {
public String id;
public String text;
public Date start_date;
public int duration; // default: nextedy.gantt.default.task_duration (10)
public float progress;
public String parent;
public String type;
public String url;
public String itemId;
public String projectId;
public boolean readonly;
public boolean unplanned; // default: false
public boolean open; // default: !nextedy.gantt.default.do_expand
public String color; // default: nextedy.gantt.default.task_color
private Map<String, String> fields;
public Map<String, String> getFields() { ... }
public void setFields(Map<String, String> fields) { ... }
}| Property | Type | Description | Example |
| id | string | Internal Gantt task identifier | task.id |
| text | string | Label displayed in the Gantt chart | task.text = wi.getId() + " - " + wi.getTitle(); |
| start_date | date | Start date on the timeline | task.start_date = wi.getStartDate(); |
| duration | int | Duration in days | task.duration = 5;; |
| progress | float | Completion: 0.0 = not started, 1.0 = done | task.progress = 0.75; |
| parent | string | Parent task ID for hierarchy | task.parent = "TASK-100"; |
| type | string | Task type (e.g. "milestone", "workpackage") | task.type = "milestone"; |
| url | string | URL opened when the task label is clicked | task.url = wi.getUri().toString(); |
| itemId | string | Work item ID | task.itemId |
| projectId | string | Polarion project ID | MYPROJECT |
| readonly | boolean | Prevents drag/resize in the chart | task.readonly = true; |
| unplanned | boolean | Marks the task as having no scheduled start | task.unplanned = true; |
| open | boolean | Whether children are expanded by default | task.open = true; |
| color | string | Task bar color (CSS color or hex) | task.color = "#e6b8a2"; |
For any assistance, please don’t hesitate to reach out by submitting a ticket here.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article