Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I want a custom field ( Single user picker) to pick a user from project role and update

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)

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,934 views 11 5
Join discussion

Community Events

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

Events near you