Conditions

Availability

This feature is available for the Jira server deployment option only. We plan to add it to the Cloud version in the near future.

Conditions control who can perform a transition and the circumstances under which they can perform this transition. If any part of a transition's condition fails, the user will not see the transition link on the 'view issue' page.

You can use Power Scripts™ for Jira and SIL™ to define a large set of conditions beside Jira's built-in conditions, by just adding a (k) SIL™ Condition to the transition and publishing the workflow, as described here.

The following common examples explain this feature:

Required apps

Power Scripts™ for Jira (server)

Level: BASIC

Previous status

A workflow condition that enables you to disable a particular transition if the current issue has never been in a specific status:

SIL Code
number STATUS_RESOLVED = 5;
string[] status_history = fieldHistory(key, "status");

return elementExists(status_history, STATUS_RESOLVED);

You can also check if the current issue was not in a specific status just before it entered the current status:

SIL Code
number STATUS_OPEN = 1;
string[] status_history = fieldHistory(key, "status");
string previous_status = getElement(status_history, size(status_history)-3);

return previous_status == STATUS_OPEN;

Cascading select comparer

A workflow condition that allows you to disable a particular transition when two cascading selects are equals:

Let's suppose the cascading select custom fields are named `CASCADING 1` and `CASCADING 2` and their custom fields ids are `customfield_10000` and `customfield_10001`:

Cascading select comparer
//Condition Cascading select comparer

if(length(#{CASCADING 1}) == 0 && length(#{CASCADING 2}) == 0) { //both cascading select are empty
   return true;
}
if(#{CASCADING 1} == #{CASCADING 2}) {
   return true;
}
return false;

Equivalent to:

Cascading select comparer
//Condition Cascading select comparer

if(length(customfield_10000) == 0 && length(customfield_10001) == 0) { //both cascading select are empty
   return true;
}
if(customfield_10000 == customfield_10001) {
   return true;
}
return false;

Condition based on regular expression

A workflow condition that allows you to disable a particular transition when a custom field value doesn't match to a regular expression:

For instance, let's create a custom field select, named `Combo`, with the following options: `accepted.1234567890.text-123`, `accepted.0987654321.othertext-123456` and `notaccepted-456`.

The transition will be present for the workflow if the value of the custom field will match to the regular regular expression for values like `accepted.1234567890.text-123` or `accepted.0987654321.othertext-123456`. Value `notaccepted-456` doesn't match to the regular expression, so the transition will not be present when the custom field has this value.

The expressions matching to the custom field value have the following form: string "accepted." followed by exactly 10 numbers, then it is followed by ".", then the expression is followed by a alpha text only. The following character is "-" and finally it has some numbers.

Condition based on regular expression
//Condition based on regular expression

return matches(Combo, "accepted(.)(\\\\d+\\\\.?){10}(.)[a-z]+(-)(\\\\d+\\\\.?)");

Condition based on linked issues

A workflow condition that allows you to disable a particular transition when the current issue has no linked issues:

Condition on linked issues
//Condition on linked issues

return size(linkedIssues(key)) > 0;

Condition on non-linked issue

A workflow condition that allows you to disable a particular transition when the current issue has linked issues:

Condition on non-linked issue
//Condition on non-linked issue

return size(linkedIssues(key)) == 0;

Condition based on mathematical expression

A workflow condition that allows you to disable a particular transition when the mathematical expression calculated does not accomplish the script condition:

Condition based on mathematical expression
//Condition based on mathematical expression

number n = rand() + e();
return n >= 1;

To be more specific, rand() generates a number in interval [0, 1] and e() is the Euler constant. The workflow condition will be not available if the sum of the random number and the Euler constant is less than 1.

More details can be found on Math routines section.

Condition based on date-time expression

A SIL condition which checks if due date is before the day after tomorrow:

SIL Code
return dueDate > (currentDate() + "2d");

More useful date routines can be found in the Date Routines section. 

Compare two parsed texts

A SIL condition which checks if description contains summary:

SIL Code
return contains(description, summary);

Except assignee Condition

A workflow condition that allows you to disable a particular transition when the current logged in user is not the issue assignee user.

Except assignee condition
//Except assignee condition

return currentUser() == assignee;

Except reporter condition

A workflow condition that allows you to disable a particular transition when the current logged in user is not the issue reporter user.

Except reporter condition
//Except reporter condition

return currentUser() == reporter;

Except in project role condition

A SIL condition that allows you to disable a particular transition when the current logged in user is not in a given project role:

SIL Code
string ROLE = "Administrators";
return isUserInRole(currentUser(),project, ROLE);

Only/Except users in custom field

A SIL condition that allows you to disable a particular transition when the current logged in user is in a multi user picker custom field (eg Team):

SIL Code
return elementExists(Team, currentUser());

If you want the transition to be available to any user except the ones from the multi user picker cf Team, you have to negate the previous condition:

SIL Code
return !elementExists(Team, currentUser());

Users in a field are/aren't in a project role

A SIL condition that makes a transition available only if all users in multi user picker custom field Team are in project role Developers:

SIL Code
string ROLE = "Developers";
for(string user in Team) {
    if(!isUserInRole(user, project, ROLE)) {
       return false;
    }
}

If you want to disable the transition if at least one user from multi user picker cf Team is in role Administrators, use the following:

SIL Code
string ROLE = "Administrators";
for(string user in Team) {
    if(isUserInRole(user, project, ROLE)) {
       return false;
    }
}

A custom field is/isn't initialized

A SIL condition that allows you to disable a particular transition if a custom field is not initialized:

SIL Code
return isNotNull(customfield_10000);

If you want to disable the transition if field is initialized you should use:

SIL Code
return isNull(customfield_10000);

Check user property

A SILcondition which checks if a user property has a certain value:

SIL Code
string COUNTRY = "Romania";
return getUserProperty(currentUser(), "country") == COUNTRY;

Condition based on boolean expression

Control if a transition can be executed if the logged work time is less than the estimated time.

return timeSpent <= originalEstimate;

Condition based on String equality

Decide if a transition should be disabled using string equality.

return currentUser() == "admin";

Use currentUser() to get the current logged in user.

Condition based on date comparison 

Use created and updated to compare 2 dates.

return created < updated;

To get the currentDate, you can use currentDate() routine.

Condition based on comparison of numeric fields

Create 2 custom fields of type numeric and compare them in a condition.

return customfield_11300 < customfield_11301;

Where customfield_11300 and customfield_11301 are Jira custom fields of type numeric.

Condition based on equality of time spans

A SIL condition which checks if there are less than 3 days and a half remaining before the estimated time will be exceeded:

interval tstRemaining = "3d 4h";

return tstRemaining < (estimate - timeSpent);

In the example above it is used the substraction between estimate and timeSpent, but the user can also use addition between two time intervals in SIL.

All sub-tasks must be resolved

The transition won't be shown unless all sub-tasks are resolved. You can also specify a particular resolution that the sub-tasks must be in (in our example Fixed):

string[] subtasks = subtasks(key);
for(string subtask in subtasks) {
    if(%subtask%.status != "Resolved" || %subtask%.resolution != "Fixed") {
       return false;
    }
}

See also