I do not pretend that this is the most elegant solution, but it works for my org. I am running Jira Data Center in a two-node cluster. Currently on 8.20.1, Scriptrunner 6.38.0, and JSU Automation Suite 2.32.0
What needs to be configured prior to creating the listener:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
def relDateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Release Date').first()
def startDateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Start Date').first()
def versNameField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Version Name').first()
def actionField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Action').first()
def versManager = ComponentAccessor.getVersionManager()
def actionValue = issue.getCustomFieldValue(actionField) as String
def startDateValue = issue.getCustomFieldValue(startDateField) as Date
def relDateValue = issue.getCustomFieldValue(relDateField) as Date
def versNameValue = issue.getCustomFieldValue(versNameField) as String
def projId = issue.getProjectId()
def versionList = issue.getFixVersions()
Date versRelDate
Date versStartDate
if (startDateValue && relDateValue)
{
return true
}
if (!startDateValue && !relDateValue)
{
return true
}
versionList.each
{
if (relDateValue)
{
versStartDate = it.getStartDate()
if (versStartDate?.compareTo(relDateValue) >=0 && versStartDate != null)
{
throw new InvalidInputException("Start Date must be before Release Date on ${it.getName()}")
return false
}
}
if (startDateValue)
{
versRelDate = it.getReleaseDate()
if (versRelDate?.compareTo(startDateValue) <=0 && versRelDate != null)
{
throw new InvalidInputException("Start Date must be before Release Date on ${it.getName()}")
return false
}
}
}
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.project.Project
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleManager
def projRoleMan = ComponentAccessor.getComponent(ProjectRoleManager.class)
def projRoleVersMan = projRoleMan.getProjectRole("Version Manager")
def projRoleAdmin = projRoleMan.getProjectRole("Administrators")
def proj = issue.getProjectObject()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (projRoleMan.isUserInProjectRole(user, projRoleVersMan, proj) || projRoleMan.isUserInProjectRole(user, projRoleAdmin, proj))
{
return true
}
throw new InvalidInputException("You do not have permission to create Releases in this project")
def actionField = getFieldByName("Action")
def versNameField = getFieldByName("Version Name")
def relDateField = getFieldByName("Release Date")
def startDateField = getFieldByName("Start Date")
def fixVersField = getFieldByName("Fix Version/s")
def actionValue = actionField.getValue()
if (actionValue == "Create")
{
versNameField.setHidden(false)
versNameField.setRequired(true)
relDateField.setHidden(true)
relDateField.setRequired(false)
startDateField.setHidden(true)
startDateField.setRequired(false)
fixVersField.setHidden(true)
fixVersField.setRequired(false)
}
if (actionValue == "Update")
{
versNameField.setHidden(false)
versNameField.setRequired(false)
relDateField.setHidden(false)
relDateField.setRequired(false)
startDateField.setHidden(false)
startDateField.setRequired(false)
fixVersField.setHidden(false)
fixVersField.setRequired(true)
}
if (actionValue == "Release")
{
versNameField.setHidden(true)
versNameField.setRequired(false)
relDateField.setHidden(false)
relDateField.setRequired(false)
startDateField.setHidden(false)
startDateField.setRequired(false)
fixVersField.setHidden(false)
fixVersField.setRequired(true)
}