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

Why can I not set assignee by ID? (Script Runner)

Kyle Moseley Oct 15, 2014

I guess I'm misunderstanding something fundamental here. I'm running this script in the Script Console (Script Runner) and it will not assign the reporter to the issue. I don't want a work around, I'm just trying to understand how the different user objects work. 

I also tried using Script Runner's built in "setAssigneeId" in fast tracks and it did not work, coming from a fast track on the Create transition.

So, what am I missing here?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager
//import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

ComponentManager componentManager = ComponentManager.getInstance();
IssueManager issueManager = componentManager.getIssueManager()
MutableIssue issue = (MutableIssue) issueManager.getIssueObject("TFCT-9")

x = issue.getReporterId()

return x

2 answers

1 accepted

2 votes
Answer accepted
JamieA Oct 15, 2014

Your basic issue is you are not saving the issue back to the db, so you could just add

But that won't reindex the issue so you won't be able to find it in searches until someone else edits it.

The correct and best way to do it is use IssueService:

def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def validateAssignResult = issueService.validateAssign(user,, issue.reporterId)
issueService.assign(user, validateAssignResult)

This will handle validation, saving, indexing, firing events if necessary, all of which you'd have to do manually with your method.

Not to say it's always wrong to handle this stuff yourself, but you need to be aware of what happens under the covers.

There is more to it than the above, context is all important. The above code is for a completely standalone transaction, outside of a workflow event. If you are running code in a transaction, and it runs before the build-in functions "Store an issue" and "Reindex the issue", the below code will work fine (and is correct):

issue.assigneeId = issue.reporterId

If you do it as above, the change history will show this change in the same change group as any other fields changed.

Would that also solve the issue of the Fast Track's additional code not assigning?

Sorry, I've lost track of all the fast-track problems.

Most of the built-in scripts that do things to issues take additional code. They do things using the IssueService, which takes an IssueInputParameters. This is in the binding, so in fast-track you'd use:

Kyle Moseley Oct 15, 2014

As always, wonderful help. Added that and it works in Script Console. Would that also solve the issue of the Fast Track's additional code not assigning?

JamieA Oct 15, 2014

No problem. I expanded the answer a bit. Keep experimenting though!

JamieA Oct 15, 2014

I was thinking of trying to standardise the different ways of updating issues in the Additional code section, not come up with anything concrete yet though.

Kyle Moseley Oct 15, 2014

Thanks for expanding, very informative.

0 votes
Kyle Moseley Oct 15, 2014

Also, x returns a string of the user ID, so we know that getReporterId() is working.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Here’s what we’re doing to make Jira Cloud faster

Hello Community 🤗 I’m Nikhil, a Product Manager on the Jira Cloud team working on performance improvements. Performance is an ongoing journey and we continue to invest heavily in it. We under...

140 views 1 19
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