Last active
January 19, 2023 07:20
-
-
Save jweisman/f15cdbf2f3ead577b69a to your computer and use it in GitHub Desktop.
Script to validate the existence of several custom fields on transition using the ScriptRunner plugin for Jira.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.opensymphony.workflow.InvalidInputException | |
import com.atlassian.jira.ComponentManager | |
import com.atlassian.jira.issue.Issue | |
import com.atlassian.jira.issue.CustomFieldManager | |
import com.atlassian.jira.issue.fields.CustomField | |
def customFieldManager = ComponentManager.getInstance().getCustomFieldManager() | |
def fields = [] | |
// For Alma issues, if issue is fixed, make all sorts of validations | |
if (issue.resolution?.name == 'Fixed' && issue.project?.name == 'Alma') { | |
switch ( issue.issueType?.name ) { | |
case 'Bug': | |
fields.addAll(['Resolution Description','Fix in Environment']) | |
case ['Story', 'Bug', 'Task', 'inList']: | |
fields.addAll(['Documentation Required','Migration Impact','Configuration Impact','Automation Impact','Leganto Documentation Required']) | |
} | |
fields.each { | |
CustomField cf = customFieldManager.getCustomFieldObjectByName(it) | |
if (cf && !issue.getCustomFieldValue(cf)) { | |
if (invalidInputException) | |
invalidInputException.addError(cf.id, "You must specify a value for ${cf.name}.") | |
else | |
invalidInputException = new InvalidInputException(cf.id, "You must specify a value for ${cf.name}.") | |
} | |
} | |
if (invalidInputException) | |
invalidInputException.addError("The fields marked below must be filled before the issue can be resolved.") | |
} else | |
return true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment