Heads up! ScriptRunner documentation is moving to docs.adaptavist.com. Adaptavist will keep this site up for a bit, but no future updates to documentation will be published here. ScriptRunner 6.20.0 will be the last release to link to scriptrunner.adaptavist.com for in-app help.

Conditions 'translated' into groovy script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the changed field
def exampleField = getFieldById(getFieldChanged())

if (currentUser == underlyingIssue.reporterUser && currentUser == underlyingIssue.assignee) { (1)
} else {

if (ComponentAccessor.getGroupManager().getGroupsForUser(currentUser)?.find { it.name == "jira-administrators" }) { (2)
} else {

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def devProjectRole = projectRoleManager.getProjectRole("Developers")
if (currentUser.key == "luke" || projectRoleManager.isUserInProjectRole(currentUser, devProjectRole, underlyingIssue.getProjectObject())) { (3)
    exampleField.setError("You are either Luke or you belong to Developers project role and you cannot edit the field")
} else {

if (currentUser == underlyingIssue.projectObject.getProjectLead()) { (4)
    exampleField.setDescription("Current User is project lead")
} else {

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Multi User Picker CF")
if (currentUser == underlyingIssue.getCustomFieldValue(cf) || currentUser in underlyingIssue.getCustomFieldValue(cf)) { (5)
    getFieldById("description").setFormValue("Current user is member of the Multi User Picker custom field")
} else {
    getFieldById("description").setFormValue("Current user is not member of the Multi User Picker custom field")

def cf2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Single Group Picker CF")
def groupsToCompare = underlyingIssue.getCustomFieldValue(cf2) as ArrayList
if (ComponentAccessor.getGroupManager().getGroupsForUser(currentUser.key)?.disjoint(groupsToCompare)) { (6)
} else {

if (getActionName() == "Start Progress" || getDestinationStepName() == "Done") { (7)
} else {
1 If current user is reporter AND current user is current assignee make the changed field hidden, else shown
2 If current user in group 'jira-administrators' allow the inline edit of the changed field
3 If current user is 'luke' or current user in project role 'Developers' make the changed field read-only and show an error message, else clear the error and make the field editable again
4 If current user is Project Lead add a description at the changed field, else clear the description
5 If current user in user custom field value add a default value in the description
6 If current user in group custom field value then make the changed field required, else optional.
7 If workflow Action is 'Start Progress' or workflow Step is 'In Progress' then make the changed field required, else optional.

Have questions? Visit the Atlassian Community to connect, share, and learn with other Atlassian users and experts, including Adaptavist staff.

Ask a question about ScriptRunner for JIRA, Bitbucket Server, or Confluence.

Want to learn more? Check out courses on Adaptavist Learn, an online platform to onboard and train new users for Atlassian solutions.