What API can I use in Item Script?

Modified on Wed, 28 Aug 2019 at 06:38 PM

The widget partameter Advanced > Item Script is there, to let you prepare the data to be sent to the client. You can use the data later, e.g. to change the template of what is rendered to the right of the task, or tooltip, see eg:  How to change text on right?


In this article we dive deeper into the Item Script


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.


There are two variables defined:

  • task of type com.nextedy.polarion.gantt.model.Task
  • wi of type com.polarion.alm.tracker.model.IWorkItem



In other words, the typical task is to read some data from the source server side object (wi) and pass it to the client as serialised object (task).

Usually you call task.getFields().put(KEY,VALUE)


Example, render the assignee field and pass it to the client:

if(wi.type.id==='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);
    } 
}


From API point of view, here is Task.class definition: 


public class Task  {
    public String id;
    public String text;
    public Date start_date;
    public int duration = Integer.getInteger("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 = false;
    public boolean open = !Boolean.getBoolean("nextedy.gantt.default.do_expand");
    public String color = System.getProperty("nextedy.gantt.default.task_color",null);

    private Map<String,String> fields = new HashMap<String, String>();

    public Map<String, String> getFields() {
        return fields;
    }

    public void setFields(Map<String, String> fields) {
        this.fields = fields;
    }

}

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 atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article