Sample Rules for automation


App configuration: tab "Rules"

All samples below have to be entered into the text field on tab "Rules". These rules will be executed automatically for all traffic light fields.


Set a default value for traffic-light "Criticality" to "yellow"

if (issue.status.name == "To Do" && issue.trafficLight("Criticality") == null) issue.trafficLight("Criticality", "(,yellow,) yellow");

The status name has to be adjusted according to your workflow (creating an issue would result into this target status).

Set traffic-light "Criticality" to yellow if overdue (here: due before yesterday)

if (new Date(issue.duedate).getTime() < (new Date()).getTime() - 864000) issue.trafficLight("Criticality", "(,yellow,) yellow");

A day has got 864000 milliseconds: yesterday is yet - 1 day = new Date().getTime() - 864000. For comparison, use the datetime in milliseconds.

Set traffic-light "Criticality" of parent to subtask's "Criticality"

// Having multiple subtasks, the last update will overwrite all others:

var myCriticality = issue.trafficLight("Criticality");
if (issue.parent) {
    issue.use(issue.parent.key, function(parent) {
         if (parent.trafficLight("Criticality") != myCriticality) parent.trafficLight("Criticality", myCriticality);
    });
}

Using this scenario, the a subtask modification will update its parent: having multiple subtasks, the last update will overwrite all others.

What you can also do: check the parent's traffic-light field's content and update this in case of a higher severity instead of inequality like in the sample above, only.

Set traffic-light "Criticality" of inward/outward linked issue(s) to current issue's "Criticality"

// Having multiple linked target issues, the last update will overwrite prior settings of the linked source issue:

var myCriticality = issue.trafficLight("Criticality");
issue.inward("relates to", function(linkIssue) {
    if (linkIssue.trafficLight("Criticality") != myCriticality) linkIssue.trafficLight("Criticality", myCriticality);
});

Depending on the link direction, you can use issue.inward() or alternatively issue.outward() for the opposite link direction. The first parameter is the issue link type's direction name. Here: "relates to" is used, which is the same for both link directions whereas inward:"is blocked by" and outward:"blocks" in case of the issue link type "Blocks".

Get value of 2 fields (system field or custom field by names) and set traffic-light based on comparison of both field values


var field1_name = "Technical Knowledge";
var field1_index = trafficLight.systemfields.map(function(field) { return field.name }).indexOf(field1_name);
var field1_value = (field1_index > -1 ? issue[trafficLight.systemfields[field1_index].id] : "");
console.log("user defined rule: retrieve value of field '"+ field1_name + "' = " + field1_value);

var field2_name = "Developing";
var field2_index = trafficLight.systemfields.map(function(field) { return field.name }).indexOf(field2_name);
var field2_value = (field2_index > -1 ? issue[trafficLight.systemfields[field2_index].id] : "");
console.log("user defined rule: retrieve value of field '"+ field2_name + "' = " + field2_value);

if (field1_value < field2_value) issue.trafficLight("Usability", "(,,red) red");

Get an option field and 2 date-picker fields to set a traffic-light based on comparison

Having configured an option field named "project size" with options "small", "medium" and "large" and a new date-picker custom field "current due date" and use of Jira's build-in field "due date", you can retrieve the content of that 3 fields and compare them to determine automatic setting of traffic-light field named "Indicator":


var field1_name = "Due Date";
var field1_index = trafficLight.systemfields.map(function(field) { return field.name }).indexOf(field1_name);
var dueDate = (field1_index > -1 ? new Date(issue[trafficLight.systemfields[field1_index].id]) : 0);

var field2_name = "Current Due Date";
var field2_index = trafficLight.systemfields.map(function(field) { return field.name }).indexOf(field2_name);
var currentDueDate = (field2_index > -1 ? new Date(issue[trafficLight.systemfields[field2_index].id]) : 0);

var field3_name = "Project Size";
var field3_index = trafficLight.systemfields.map(function(field) { return field.name }).indexOf(field3_name);
var projectSize = (field3_index > -1 ? issue[trafficLight.systemfields[field3_index].id].value : "");

if (projectSize == "Small") {
  console.log("project size is small: diff. of due dates = " + (currentDueDate - dueDate));
  if (dueDate == currentDueDate) {
    issue.trafficLight("Indicator", "(green,,) green");
    console.log("due date is equal to current due date");
  } else if (currentDueDate - dueDate > 0 && (currentDueDate - dueDate) / 86400000 <= 14) {
    issue.trafficLight("Indicator", "(,yellow,) yellow");
    console.log("current due date is greater than due date but max. 14 days");
  } else if ((currentDueDate - dueDate) / 86400000 > 14) {
    issue.trafficLight("Indicator", "(,,red) red");
    console.log("current due date is greater due date more than 14 days");
  }
}

Synchronize the content of a Traffic-Light with a Customfield

If you want to automatically synchronize the content of a Traffic-Light field with one of Jira's custom fields, you can easily do that:

Having done this, you have to enter the related rule to synchronize:

Finally, you have to configure your SCRUM or KANBAN board to display the new custom field on your issues' card:

The only disadvantage of Jira Cloud is, that based on different technologies in the background in opposite to the Jira Server Edition, the traffic-light content cannot be rendered as graphic sign - just as text on the card by its label. But that's nothing, any third-party vendor can influence!