...
...
...
...
...
...
...
...
...
...
...
...
Table of Contents |
---|
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. |
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.
...
NOTE: Some scripts will rely on a transition screen being present in the selected transition. See the example below:
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.
...
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; } |
...
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; } |
...
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; } } |
...