> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nextedy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Marker Factory API

> The Marker Factory API in Nextedy GANTT provides server-side methods for adding vertical milestone markers to the Gantt chart timeline.

export const LastReviewed = ({date}) => {
  if (!date) return null;
  const formatted = new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric",
    timeZone: "UTC"
  });
  return <p className="mt-10 text-sm text-gray-400 dark:text-zinc-500 not-prose">
      Last reviewed on {formatted}
    </p>;
};

Configure the Markers Script in **Widget Parameters > Advanced > Markers Script**.

## Script Variables

The following variables are available in the Markers Script scope:

| Variable         | Type                 | Description                                                                        |
| ---------------- | -------------------- | ---------------------------------------------------------------------------------- |
| `markerFactory`  | MarkerFactory        | Factory object for creating and registering timeline markers.                      |
| `trackerService` | ITrackerService      | Polarion tracker service for querying work items and projects via Lucene queries.  |
| `config`         | Configuration object | The current Gantt configuration, including page parameters and context project ID. |

## MarkerFactory Methods

| Method                                                         | Return Type | Description                                                                                                                |
| -------------------------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------- |
| `markerFactory.addMarker()`                                    | Marker      | Create and register a new empty marker object. Set its properties using the marker methods below.                          |
| `markerFactory.addMarker(text, date)`                          | Marker      | Utility method that creates a marker with the specified text label and date string. Date format: `"YYYY-MM-DD"`.           |
| `markerFactory.addPlanMarkers(query, color)`                   | void        | Query Polarion plans matching the Lucene query and add a marker for each plan's start or end date.                         |
| `markerFactory.addWorkItemMarkers(query, dateProperty, color)` | void        | Query Polarion work items matching the Lucene query and add a marker for each work item using the specified date property. |

## Marker Object Methods

The marker object returned by `addMarker()` provides these methods:

| Method                     | Parameter Type   | Description                                                                                                           |
| -------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------- |
| `marker.setText(text)`     | `String`         | Set the text label displayed on the marker line.                                                                      |
| `marker.setTitle(tooltip)` | `String`         | Set the tooltip text displayed when hovering over the marker.                                                         |
| `marker.setDate(date)`     | `java.util.Date` | Set the marker date using a Java Date object.                                                                         |
| `marker.setDate(dateStr)`  | `String`         | Set the marker date using a date string. Format: `"YYYY-MM-DD"`.                                                      |
| `marker.setColor(color)`   | `String`         | Set the marker color. Must be one of the 16 basic HTML color names (e.g., `"red"`, `"blue"`, `"green"`, `"fuchsia"`). |

<Note title="Marker Tooltip Format">
  Hovering over a milestone marker displays a tooltip in the format:
  `Milestone: <name>` followed by `Due Date: <YYYY-MM-DD>`.
</Note>

## Marker Positioning

Markers render at the **end of the specified date** by convention. If you need a marker to appear at the start of a date, subtract one day from the date value.

<Tip title="End-of-Day Rendering">
  By design, a marker set to `"2025-08-04"` renders at the end of August 4th. To position it at the start of August 4th, set the date to `"2025-08-03"` instead.
</Tip>

## Manually Adding a Marker

Create a marker with explicit values:

```javascript theme={null}
var marker = markerFactory.addMarker();
marker.setText("20.0");
marker.setDate("2025-08-04");
marker.setColor("green");
```

Using the shorthand method:

```javascript theme={null}
markerFactory.addMarker("test", "2019-01-30");
```

## Adding Markers from Plans

Pull markers automatically from Polarion plans matching a Lucene query:

```javascript theme={null}
markerFactory.addPlanMarkers("template.id:iteration AND project.id:gantt2", "blue");
```

* `template.id:iteration` -- filters plans by template ID
* `project.id:gantt2` -- restricts to a specific project

Plan-based markers receive the CSS class `plan`, enabling distinct visual styling.

## Adding Markers from Work Items

Pull markers from Polarion work items matching a Lucene query:

```javascript theme={null}
markerFactory.addWorkItemMarkers("type:release AND project.id:gantt2", "publicLaunch", "blue");
```

* `type:release` -- filters work items by type
* `"publicLaunch"` -- the date field on the work item used to position the marker
* `"blue"` -- the marker color

### Dynamic Project ID

Use `config.getContextProjectId()` to reference the current project instead of hardcoding:

```javascript theme={null}
markerFactory.addWorkItemMarkers(
    "type:release AND project.id:" + config.getContextProjectId(),
    "publicLaunch",
    "blue"
);
```

## Dynamic Markers with Polarion API

Use `trackerService` for full scripting control over marker creation. This approach supports filtering, conditional coloring, and custom tooltip content.

### Loading Time Points

```javascript theme={null}
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());
    }
}
```

<Warning title="Polarion 2304+ Scripting Changes">
  Since Polarion version 2304, use getter methods instead of direct property access. Use `tp.getName()` instead of `tp.name`. Use `tp.getTime().getDate()` instead of `tp.time.date`.
</Warning>

### Polarion 22 R2 and Older

For older Polarion versions, use direct property access:

```javascript theme={null}
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);
    }
}
```

## Dynamic Marker Customization with Page Parameters

Combine `trackerService` with page parameters to let users control which markers appear:

```javascript theme={null}
var milestoneIds = config.pageParameters.milestone;
if (milestoneIds === null) {
    milestoneIds = "";
} else {
    milestoneIds = milestoneIds.replaceAll(',', ' ');
}

var milestones = trackerService.queryWorkItems(
    "project.id:Gantt3 AND type:milestone AND id:(" + milestoneIds + ")", "id"
).iterator();

while (milestones.hasNext()) {
    var tp = milestones.next();
    var marker = markerFactory.addMarker();
    marker.setText(tp.getTitle());
    marker.setDate(tp.getValue('releaseDate').getDate());
    var productType = tp.getValue('productType');
    marker.setColor("blue");

    if (productType !== null && productType.getId() === 'typeB') {
        marker.setColor("fuchsia");
    }
}
```

## Marker CSS Classes

| CSS Class                        | Applied To     | Description                                         |
| -------------------------------- | -------------- | --------------------------------------------------- |
| `gantt_marker`                   | All markers    | Base class applied to every marker element.         |
| `today`                          | Today marker   | Applied to the automatic today-date marker line.    |
| `plan`                           | Plan markers   | Applied to markers created by `addPlanMarkers()`.   |
| Named color class (e.g., `blue`) | Custom markers | Applied when a color is specified via `setColor()`. |

<Frame>
  <img src="https://mintcdn.com/none-17b4493f/umKaPvHwUHw-ZQFM/gantt/diagrams/reference/api/markers-api/diagram-1.svg?fit=max&auto=format&n=umKaPvHwUHw-ZQFM&q=85&s=d6dcd25977f3c1585a6a907839fa5184" alt="diagram" style={{ maxWidth: "560px", width: "100%" }} width="560" height="440" data-path="gantt/diagrams/reference/api/markers-api/diagram-1.svg" />
</Frame>

## Error Handling

* Script errors display as a warning indicator with a count badge in the Gantt toolbar
* The error message includes the prefix **Markers Script Error:**
* Errors appear in both view mode and wiki editor mode

## Configuration Example

A complete Markers Script combining plan markers, work item markers, and a manual milestone:

```javascript theme={null}
// Add iteration boundary markers
markerFactory.addPlanMarkers(
    "template.id:iteration AND project.id:" + config.getContextProjectId(),
    "blue"
);

// Add release markers from work items
markerFactory.addWorkItemMarkers(
    "type:release AND project.id:" + config.getContextProjectId(),
    "start",
    "red"
);

// Add a manual milestone
var marker = markerFactory.addMarker();
marker.setText("Go-Live");
marker.setDate("2025-12-01");
marker.setColor("green");
```

## Related Pages

* [Item Script API](/gantt/reference/api/item-script-api) -- server-side script for data preparation
* [Gantt Config Script API](/gantt/reference/api/config-script-api) -- client-side script for templates and events
* [Velocity Context Variables](/gantt/reference/api/velocity-context) -- server-side variables for dynamic script generation
* [Page Parameters API](/gantt/reference/api/page-parameters-api) -- user-input parameters for dynamic marker filtering
* [Item Color Legend](/gantt/reference/item-color-legend) -- default color behavior for task bars

<LastReviewed date="2026-07-02" />
