Hi,
I want a custom field ( Single user picker) to pick a user from the project role and update but if the user in project role and reporter are the same it should clear the custom field and update with a default value. Please help in achieving it.
The below code only updates the field but does not clear the field if the project role user and the reporter are the same.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
def groupManager = ComponentAccessor.groupManager
def issue = issue as Issue
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = ComponentAccessor.getComponent(IssueService)
def issueInputParameters = issueService.newIssueInputParameters()
ComponentManager componentManager = ComponentManager.getInstance()
//ProjectManager projectManager = componentManager.getProjectManager()
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
// name of role here
ProjectRole controllerRole = projectRoleManager.getProjectRole("Controller")
ProjectRoleActors controller = projectRoleManager.getProjectRoleActors(controllerRole, issue.projectObject)
def controllerField = customFieldManager.getCustomFieldObjectByName("Controller")
def actor = controller.getApplicationUsers()
actor.remove(issue.reporter)
controllerField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(controllerField), actor), changeHolder)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.