YouTrack Server 2026.1 Help

Custom Scripts

Custom scripts let you organize and reuse blocks of code. They don't contain any specific type of rule. Instead, they contain code that can be used in other scripts.

Custom scripts are stored as modules inside a workflow that was created using the JavaScript Editor. To add a custom script, open or create a JavaScript workflow in Administration > Workflows, then use the Add module control in the editor sidebar and select the template for a custom script.

In any script, you can define whichever objects and functions you want to use in other scripts by assigning them as properties of the exports object.

Here's an example.

First, we'll create a custom script that defines a simple function.

// 'math.js' exports.f = function (x) { return x * x - 6 * x + 13; }; // And these are a couple of constants we need. exports.lower = 0; exports.upper = 9;

When you load this script in another file with require('./math'), YouTrack returns an object that contains the properties that you defined for the exports object. In this example, that object is assigned to the math constant, so you can access the function as math.f.

Next, we'll write an action rule that references this function.

// 'chart.js' const entities = require('@jetbrains/youtrack-scripting-api/entities'); const math = require('./math'); exports.rule = entities.Issue.action({ title: 'Draw a chart', command: 'draw', action: (ctx) => { const issue = ctx.issue; var chart = ''; for (var x = math.lower; x <= math.upper; x++) { var fx = math.f(x); var line = x + ' | '; for (var i = 0; i < fx; i++) { line = line + "#"; } chart = chart + line + "\n"; } issue.addComment(chart); } });
23 April 2026