Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to make field editable by Component Lead using behaviours

avinashp July 15, 2019

I would like to set the field components read only except for component leads using behaviours. Any ideas on how to achieve this ?

1 answer

1 accepted

1 vote
Answer accepted
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2019

if you don't have components field on a screen (meaning you can't change them while making a transition or editing issue) then put this in initializer:

import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
getFieldByName("your field name").setReadOnly(true)
if (currentUser.name in underlyingIssue.components*.lead) {
getFieldByName("your field name").setReadOnly(false)
}

if it's on the screen, put this into component's code :

import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def yourField = getFieldByName("your field name")
if (currentUser.name in getFieldById(getFieldChanged()).value*.lead) {
yourField.setReadOnly(false)
} else {
yourField.setReadOnly(true)

edit:

I thought it's about making field editable only for component leaders from this particular issue. guess for whole project something like this in component's field script should work:

import com.atlassian.jira.component.ComponentAccessor
def projectComponentManager = ComponentAccessor.projectComponentManager
def leads = projectComponentManager.findAllForProject(issueContext.projectId)*.lead
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
getFieldById(getFieldChanged()).setReadOnly(true)
if (currentUser.name in leads) {
getFieldById(getFieldChanged()).setReadOnly(false)
}

 

avinashp July 16, 2019

@Ilya Turov  - Thank you so much, the last snippet was what i was looking for, 

Suggest an answer

Log in or Sign up to answer