Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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
Published in Marketplace Apps & Integrations

☕️ Monday coffee with Jexo: Weekly Atlassian news roundup | 21st June 2021

Hi community 👋, as every Monday we're bringing you a quick update on what happened in the Atlassian ecosystem last week. There were a few interesting events like for example the announcement of th...

29 views 0 4
Read article

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