How to set assignee from user type custom field?

Hi Team,

 

i am trying to set Assignee value from custom type user field , but i am getting value in XXXXX(XXXXX) format.

When i am trying to set the value using issue.setAssignee() i am getting null value.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger(" ")
log.setLevel(Level.DEBUG)


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
UserManager userManager = ComponentAccessor.getUserManager();

def managerId = customFieldManager.getCustomFieldObjectByName("Dept Approver's(Manager) Id")
String  managerIdvalue =issue.getCustomFieldValue(managerId)

ApplicationUser Mgruser = userManager.getUserByName(managerIdvalue)


log.info "managerId: "+managerId
log.info "managerIdvalue: "+managerIdvalue
log.info "Mgruser : "+Mgruser

issue.setAssignee(Mgruser )
//issue.setAssignee(Mgruser )

 

 

==========OUT PUT============

 

2017-08-09 10:50:20,455 INFO [ ]: managerId: Dept Approver's(Manager) Id
2017-08-09 10:50:20,456 INFO [ ]: managerIdvalue: 44018514(44018514)
2017-08-09 10:50:20,456 INFO [ ]: Mgruser : null

 

issue.setAssignee(Mgruser) --> should assign the value of "Mgruser " into Assignee.

but "Mgruser" is getting null value.

please advise how to get username from coustomfield and  set it to Assignee default field.

 

1 comment

getUserByName expects to be passed a user name, which in JIRA-speak means the login id.  Do you really have a user who logs in with that number as their login?

yes, we have users with username as numerical ids and full name as usual. i need to assign user with this numerical id.

Comment

Log in or Sign up to comment
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

73 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you