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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,477
Community Members
 
Community Events
176
Community Groups

How can I move a user from a custom text field to assignee field?

I have a script that grabs the value of a text field, which is the user id of the user. For example the text field has a value of 432100. Before the changes for gdpr the script worked great, in fact it still works great for users that were created before the change. Now any user created after the change, the assignee field updates with the numbers but doesn't find the user. The assignee field will just have 432100 - ?. How would I fix this? Please be gentle, I don't really code :) Script below:

 

import com.atlassian.jira.component.ComponentAccessor


// Get required Managers

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// get a pointer to the Implemented By user picker field and its value

def userCf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Project Lead")

def implUser = issue.getCustomFieldValue(userCf)

// If the Implemented By Field is not null then set the assignee

if(implUser){

    issue.assigneeId = implUser

}

1 answer

1 accepted

0 votes
Answer accepted
Florian Bonniec Community Leader Dec 14, 2022

Hi @Tim Perrault 

 

You have to get the object that represent the user instead the user id. You can do it using userManager class.

Base on the code available here

I've create a script that I've not tested but should work. Btw, the website mention have lot of usecase you can use.

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.IssueInputParametersImpl

import com.atlassian.jira.event.type.EventDispatchOption

// Get required Managers

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// get a pointer to the Implemented By user picker field and its value

def userCf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Project Lead")

String implUser = issue.getCustomFieldValue(userCf)

//Dependency to save issue update

def issueService = ComponentAccessor.issueService

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// If the Implemented By Field is not null then set the assignee

if(implUser){

    def userManager = ComponentAccessor.getUserManager()

    def user = userManager.getUserByName(implUser)

    if(user){

        def issueInputParameters = new IssueInputParametersImpl()

        issueInputParameters.setAssignee(user)

        def updateValidationResult = issueService.validateUpdate(loggedInUser, issue.id, issueInputParameters)

        assert updateValidationResult.valid : updateValidationResult.errorCollection

        def issueUpdateResult = issueService.update(loggedInUser, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, sendMail)

        assert issueUpdateResult.valid : issueUpdateResult.errorCollection

    }

}

 

 

Regards

I kept on getting errors from your script about the object type, but you got me going down the right path. Basically needed to turn the string into an application user. Thanks for the help. I was able to get it working with the code below:

 

import com.atlassian.jira.component.ComponentAccessor

// Get required Managers

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// get a pointer to the Implemented By user picker field and its value

def userCf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Project Lead")
String implUser = issue.getCustomFieldValue(userCf)

//Dependency to save issue update


def
issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def user = ComponentAccessor.userManager.getUserByName(implUser)

// If the Implemented By Field is not null then set the assignee
     if(implUser){
      issue.setAssignee(user)
       }

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.6
TAGS

Atlassian Community Events