"Could you please use the script below in Scriptrunner behavior? It will be helpful for you."
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
// Get the Project Role Manager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def financeRole = projectRoleManager.getProjectRole("Finance") // Replace with your actual project role name
// Get the current user and project
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def project = issueContext.projectObject
def totalRevenueField = getFieldById(getFieldChanged())
// Debugging: Print out the current user and project
log.error("Current user: ${currentUser.username}, Project: ${project?.key}")
// Check if the user has the "Finance Team" role in this project
if (projectRoleManager.isUserInProjectRole(currentUser, financeRole, project)) {
// Finance users: Show the field and make it editable
totalRevenueField.setHidden(false)
totalRevenueField.setReadOnly(false)
log.error("User ${currentUser.username} is part of Finance Team. Showing Total Revenue field.")
} else {
// Non-Finance users: Hide the field completely
totalRevenueField.setHidden(true)
totalRevenueField.setFormValue("Empty")
log.error("User ${currentUser.username} is NOT part of Finance Team. Hiding Total Revenue field.")
}
Note: It will only support the edit and create screens. The behavior script won't directly hide the field in the view screen; you need to use the Scriptrunner fragment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.