Restrict Priority to only Administrators

We are trying to set a Behavior to restrict the priority to only

Team Members

 role.  Not sure what we are missing to get it to work.

 

 

 

import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.MutableIssue

def priorityField = getFieldById("priority")

if ( isUserMemberOfRole("Administrators")) {
priorityField.setHidden(true)
} else {
priorityField.setHidden(false) 
}

 

 

 

2 answers

Any thoughts?

Hi - I don't think that that's actually possible. 'Priority' is a built in JIRA field and cannot be truly hidden. Only custom fields of an actual 'hideable' type will behave as you are expecting via behaviors. You could maybe remove Priority from the View and Edit screens, and only show it on a workflow transition screen, where the transition had a validator to check the users group or project role when trying to execute the transition...

Open to correction by someone from he SR team of course, but you might need to try a different approach..

Not that it matters much, but your code needs a few tweaks. This is something I use to hide a custom field and it works for me

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def hideableCF = getFieldById("customfield_12345")
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def devProjectRole = projectRoleManager.getProjectRole("Team Members")
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//check if user is in correct role and unlock field
if (projectRoleManager.isUserInProjectRole(currentUser, devProjectRole, underlyingIssue.getProjectObject())) 
   { 
    hideableCF.setHidden(false)
   } 
else { // or if not, lock it
      hideableCF.setHidden(true)
     }

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

64 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you