Skip to end of banner
Go to start of banner

Validator Templates

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

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 templates will create this validation process by adding a new validation script to an existing workflow transition within Jira.

Setting up the Validator Templates

Because the validation script needs to live in an existing workflow transition the first two steps to creating a validation script template will be selecting the workflow and transition for where the validation should be place.

If you are unsure which workflow to use an easy way to check is through the “view workflow” link that will present on any issue in Jira. Make sure you use an issue for the project and issue type you wish to add the validation to.

This “view workflow” link may not always be present due to permission settings. You may need to look in the project settings in order to determine which workflow you should select.

NOTE: Some scripts will rely on a transition screen being present in the selected transition. See the example below:

Testing the Script

Testing the script is as simple as attempting to complete the transition without a comment present. In the example below, 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.

Inputs

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

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.


Field has value

Required field must have a value in the current transition screen in order for the user to complete the transition.

Inputs

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

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

NOTE: The custom field id (customfield_10626) is an example, the id of custom fields will be unique for every Jira instance. To check the id for a custom field see more information about the Custom Field Usage tool included in Power Scripts.

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.


Issue has subtasks

Current issue must have subtasks in order for the user to complete the transition.

Inputs

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

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

Linked issues in certain status

All linked issues with the given link type should be in a certain status in order for the user to complete the transition.

Inputs

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

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;
    }
}

NOTE: The name of a link type is not the same as its inward and outward description. For example, the link type of “Cloners” has an inward description of “is cloned by” and an outward description of “clones”. Understand that the values you see when linking issues are the descriptions and not the name of the link type. To view a list of link types in your system see the Issue Linking page in the Jira admin.

NOTE: When setting up this validator be sure to type the name of the status correctly.


Parent issue in certain status

The parent of the issue should be in a certain status in order for the user to complete the transition.

Inputs

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

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

Subtasks issues in certain status

All the subtasks of the current issue should be in a certain status in order for the user to complete the transition.

Inputs

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

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;
    }
}

Contents

  • No labels