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)
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 'firstname.lastname@example.org(email@example.com)'. 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)
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 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.
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.
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 'firstname.lastname@example.org(email@example.com)' string which is definitely not a username.
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 ...
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