- Problem Statements
- I cannot figure out why the read-only section is applying to all statements; it's even locking for Jira-Administrators group even though it's not applied to that statement (from what I can tell)
- How can I set the error message on the Issue Type field, to be cleared if another project is selected?
- Can this script be further optimized to improve performance? I'm sure I've got repeats and stragglers.
- Already Tried
- Removing the getFieldById(ISSUE_TYPE).with setting from individual statements and move to end
- Adding different settings to each statement (i.e. some are TRUE while others are FALSE)
- Adding setError and clearError to each statement
- Adding setError and clearError to the end
- Combining the remoteUsersRoles into a single statement but it wound up reading none of them (e.g. if ["Project Managers","Program Managers","Team Leads"] in remoteUsersRoles)
Thanks in advance to anyone who can help!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.security.roles.ProjectRoleManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
@BaseScript Field Behaviours fieldBehaviours
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def allIssueTypes = ComponentAccess.constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueTypeField = getFieldByID(ISSUE_TYPE)
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext,projectObject)*.name
def availableIssueTypes = []
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "jira-administrators")) {
availableIssueTypes.allAll(allIssueTypes.findAll {it.name in ["Initiative", "Bug","Story","Task","Epic","Problem","Incident"] })
}
if ("Project Managers" in remoteUsersRoles) {
availableIssueType.addAll(allIssueTypes.findAll {it.name in ["Initiative"] })
}
if ("Program Managers" in remoteUsersRoles) {
availableIssueType.addAll(allIssueTypes.findAll {it.name in ["Initiative"] })
}
if ("Administrators" in remoteUsersRoles) {
availableIssueType.addAll(allIssueTypes.findAll {it.name in ["Initiative"] })
}
if ("TRelease Coordinators" in remoteUsersRoles) {
def constantsManager = ComponentAccessor.getConstantsManager()
def queryIssueType = constantsManager.getAllIssueTypeObjects().find {it.name == "Sub-task" }
getFieldByID(ISSUE_TYPE).with {
setFormValue(queryIssueType.id)
setReadOnly(true)
}
}
if ("Team Leads" in remoteUsersRoles) {
def constantsManager = ComponentAccessor.getConstantsManager()
def queryIssueType = constantsManager.getAllIssueTypeObjects().find {it.name == "Sub-task" }
getFieldByID(ISSUE_TYPE).with {
setFormValue(queryIssueType.id)
setReadOnly(true)
}
}
if ("Developers" in remoteUsersRoles) {
def constantsManager = ComponentAccessor.getConstantsManager()
def queryIssueType = constantsManager.getAllIssueTypeObjects().find {it.name == "Sub-task" }
getFieldByID(ISSUE_TYPE).with {
setFormValue(queryIssueType.id)
setReadOnly(true)
}
}
if ("Testers" in remoteUsersRoles) {
def constantsManager = ComponentAccessor.getConstantsManager()
def queryIssueType = constantsManager.getAllIssueTypeObjects().find {it.name == "Sub-task" }
getFieldByID(ISSUE_TYPE).with {
setFormValue(queryIssueType.id)
setReadOnly(true)
}
}
issueTypeField.setFieldOptions(availableIssueTypes)