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

Can't copy custom field to Assignee Edited

I was trying to apply @JamieA's answer from https://community.atlassian.com/t5/Jira-questions/Why-can-I-not-set-assignee-by-ID-Script-Runner/qaq-p/87404 as we're trying to copy a string value from a custom field.

The custom field is called "Last Assignee" and is a string.

This is the relevant code (including the stuff from @JamieA's response.

def cfLastAssignee = customFieldManager.getCustomFieldObjectsByName("Last Assignee").first()
def String newAssignee = cfLastAssignee.getValue(issue)
def thisUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def validateAssignResult = issueService.validateAssign(thisUser, issue.id, newAssignee)
issueService.assign(thisUser, validateAssignResult)

I'm sure I'm missing something simple.  All suggestions welcome.

When I run the code above, it returns:

2019-09-20 15:32:00,106 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: BRUCE-1, actionId: 1031, file: <inline script>
com.atlassian.jira.exception.DataAccessException: Error while retrieving user with name 'xcarter@gumo.net(xcarter@gumo.net)'.
	at com.atlassian.jira.issue.fields.AssigneeSystemField.getUser(AssigneeSystemField.java:407)
	at com.atlassian.jira.issue.fields.AssigneeSystemField.getValueFromParams(AssigneeSystemField.java:488)
	at com.atlassian.jira.issue.fields.AssigneeSystemField.updateIssue(AssigneeSystemField.java:311)
	at com.atlassian.jira.bc.issue.DefaultIssueService.assign(DefaultIssueService.java:561)
	at com.atlassian.jira.bc.issue.IssueService$assign$3.call(Unknown Source)
	at Script2455.run(Script2455.groovy:55)

2 answers

1 accepted

0 votes
Answer accepted

@Bruce Mohler 

are you sure you need to get list of customfield objects using "getCustomFieldObjectsByName".

if you need to get only one customField object you can use getCustomFieldObject(customfiedID) and no need in this case to use first()

also second line need to be updated as below

 

def cfLastAssignee = customFieldManager.getCustomFieldObject(customfiedID)
def newAssignee = cfLastAssignee.getValue(issue).toString()

@Muhammet Adel when I execute that last line, it returns null.  I would've expected it to return a string, no?

did you used the right customFieldId. it should be like this

def cfLastAssignee = customFieldManager.getCustomFieldObject(12003)

@Muhammet Adel Is there an equivalent method using the name of the custom field?  We have a dev environment and a prod environment and, wouldn't you know, the people who set them up ended up with different custom field numbers between them.

I tried getCustomFieldObjectByName("<customFieldName>") but it didn't like that.

Obviously, I'm struggling to figure out the libraries and interfaces and am a bit overwhelmed.

Unfortunately, getCustomFieldObjectByName() is deprecated and getCustomFieldObject() is safe for your case

I'd be convinced if there were an easy to tell which server I was on (dev or prod) and provide the correct field number for that server.

I wonder why they deprecated the more portable method?

it is their decision and I don't know the reason behind it.

regarding your issue, I found this error that can be your problem, can you give a try to the solution.

DataAccessException on Issues with Assignees that Have Been Deleted from Crowd

You are trying to turn ApplicationUser into a string, while you need to get that user's username:

String newAssignee = cfLastAssignee.getValue(issue)?.username

Because that's what validateAssign expects to see, but instead it gets this weird 'xcarter@gumo.net(xcarter@gumo.net)' string which is definitely not a username.

@Ilya Turov when I paste that line into the Post Function edit window, it doesn't recognize "username" as a valid property of cfLastAssignee.

I assume I'm doing something wrong.  Suggestions?

suggestion is to ignore static type errors and still try running it :)

Suggest an answer

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

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

308 views 1 3
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