Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

Validators will prevent the user from transitioning an issue in Jira from one status to another unless the conditions for the validation are met. Validators can be used to ensure data is entered into a custom field before the user can continue, validating the format of that data, or checking some other aspect about the user or issue before allowing the transition to complete.

The template will create this validation process by adding a new validation script to an existing workflow transition within Jira.

...

Example:

...

Testing the Script

...

Testing the script is as simple as attempting to complete the transition without a comment present. Notice that the message text that was in script gets displayed to the user when the transition.

...

Templates

Comment

A comment needs to be entered in the current transition screen in order for the user to complete the transition.

...

Name

Required

Description

Description

NO

The description text will be added to a comment at the head of the script so other users can be informed of the purpose of the script.

Requires transition screen: YES

Script

Code Block
string errorMsg = "You must enter a comment!";
if(!hasInput("comment")) {
   return false, "comment", errorMsg;
}

NOTE: Because this script uses the hasInput routine it requires a transition screen. The hasInput routine is specifically designed to check the inputs of custom fields on transition screens.

...

Name

Required

Description

Customfield

YES

The custom field for which the validator is checking the presence of a value.

Description

NO

The description text will be added to a comment at the head of the script so other users can be informed of the purpose of the script.

Requires transition screen: YES

Script

Code Block
string errorMsg = "The field must have a value!";
if(!hasInput("customfield_10626")) {
   return false, "customfield_10626", errorMsg;
}

...

NOTE: Because this script uses the hasInput routine it requires a transition screen. The hasInput routine is specifically designed to check the inputs of custom fields on transition screens.

...

Name

Required

Description

Description

NO

The description text will be added to a comment at the head of the script so other users can be informed of the purpose of the script.

Requires transition screen: NO

Script

Code Block
string errorMsg = "Issue must have subtasks!";
if(size(subtasks(key)) == 0) {
    return false, errorMsg;
}

...

Name

Required

Description

Link Type

YES

The name of the link type that should be linked to the issue before it may be transitioned.

Status

YES

The workflow status name to apply the validation script to.

Description

NO

The description text will be added to a comment at the head of the script so other users can be informed of the purpose of the script.

Requires transition screen: NO

Script

Code Block
string errorMsg = "Required linked issues are not in the correct status!";
string[] blockingIssues = linkedIssues(key, "Cloners");
for(string issue in blockingIssues) {
    if(%issue%.status != "In Progress") {
       return false, errorMsg;
    }
}

...

Name

Required

Description

Status

YES

The status the parent must be set to in order for the transition to be allowed to complete.

Description

NO

The description text will be added to a comment at the head of the script so other users can be informed of the purpose of the script.

Requires transition screen: NO

Script

Code Block
string errorMsg = "Parent issue should have status Done!";
if(!isNull(parent) && parent.status != "Done") {
   return false, errorMsg;
}

...

Name

Required

Description

Status

YES

The status that all subtasks must be in before the transition is allowed to complete.

Description

NO

The description text will be added to a comment at the head of the script so other users can be informed of the purpose of the script.

Requires transition screen: NO

Script

Code Block
string errorMsg = "Subtasks are not in the In Progress!";
string[] subtasks = subtasks(key);
for(string subtask in subtasks) {
    if(%subtask%.status != "Done") {
       return false, errorMsg;
    }
}

...