What API can I use in Item Script?

Modified on Thu, 25 Jun at 3:02 PM

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.


VariableTypeDescription
taskcom.nextedy.polarion.gantt.model.TaskThe Gantt task object you will populate
wicom.polarion.alm.tracker.model.IWorkItemThe 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) { ... }
}


PropertyTypeDescriptionExample
idstringInternal Gantt task identifiertask.id
textstringLabel displayed in the Gantt charttask.text = wi.getId() + " - " + wi.getTitle();
start_datedateStart date on the timelinetask.start_date = wi.getStartDate();
durationintDuration in daystask.duration = 5;;
progressfloatCompletion: 0.0 = not started, 1.0 = donetask.progress = 0.75;
parentstringParent task ID for hierarchytask.parent = "TASK-100";
typestringTask type (e.g. "milestone", "workpackage")task.type = "milestone";
urlstringURL opened when the task label is clickedtask.url = wi.getUri().toString();
itemIdstringWork item IDtask.itemId
projectIdstringPolarion project IDMYPROJECT
readonlybooleanPrevents drag/resize in the charttask.readonly = true;
unplannedbooleanMarks the task as having no scheduled starttask.unplanned = true;
openbooleanWhether children are expanded by defaulttask.open = true;
colorstringTask 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

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article