What API I can use to add milestone markers via Markers Script ?

Modified on Mon, 13 Jan at 11:14 AM

You may want to add release or milestone markers to your GANTT widget. To do so, you can use the Advanced > Markers Script widget parameter that allows you to add custom markers via API.




The Markers Script is a script written in JavaScript language, and it is executed on the server, so you can leverage the Polarion Open API.

  • Custom milestone markers can be added via markerFactory.addMarker()call.
  • The ITrackerService is accessible via trackerService variable, so you can access various Polarion data objects (time points, plans, work items, etc...).


The following example demonstrates how to load the markers from the Polarion project timepoints:

  • Open your widget configuration, expand the Advanced Parameters, and set the following snippet to the Markers Script:
    var timePoints = trackerService.getTrackerProject("GANTT").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");
        var desc =  tp.getDescription();
        if(desc!=null){
            marker.setTitle(desc.getContent());
        }
    }


The markerFactory has following methods:

  • markerFactory.addMarker(); - create and register a new marker object
  • markerFactory.addMarker(String text, String title); - utility method if you do not have a date as java.util.Date but as a string. 
    Example: markerFactory.addMarker("test","2019-01-30")


The marker object provides the following methods:

  • void setText(String text) - set the text / name of the marker

  • void setTitle(String tooltip) - set the tooltip of the marker
  • void setDate(java.util.Date date) - set the date of the marker

  • void setDate(String dateStr) - set the date of the marker as String
    Date format is "2019-01-30"
  • void setColor(String color) - set the color of the marker.
    It must be one of the 16 basic html colors - https://www.w3.org/TR/REC-html40/types.html#h-6.5


For Polarion 22 R2 and older use the legacy API format as follows:

var timePoints = trackerService.getTrackerProject("GANTT").getTimePoints().iterator();
while(timePoints.hasNext()){
    var tp = timePoints.next();
    var marker = markerFactory.addMarker();
    marker.setText(tp.name);
    marker.setDate(tp.time.date);
    marker.setColor("fuchsia");
    var desc =  tp.description;
    if(desc!=null){
        marker.setTitle(desc.content);
    }
}

 

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