I would like to set the field components read only except for component leads using behaviours. Any ideas on how to achieve this ?
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.ComponentAccessordef currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUsergetFieldByName("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.ComponentAccessordef currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef 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.ComponentAccessordef projectComponentManager = ComponentAccessor.projectComponentManagerdef leads = projectComponentManager.findAllForProject(issueContext.projectId)*.leaddef currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUsergetFieldById(getFieldChanged()).setReadOnly(true)if (currentUser.name in leads) { getFieldById(getFieldChanged()).setReadOnly(false)}
@Ilya Turov - Thank you so much, the last snippet was what i was looking for,
It looks like you're new here. Sign in or register to get started.