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.
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()
controllerField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(controllerField), actor), changeHolder)
Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their Jira Cloud instance. ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events