Updating assignee via scriptrunner

Tayyab Bashir Community Champion Sep 08, 2017

Hi,

I am running this in ScriptRunner's console, just for testing purpose.  And I am stummed on this.
In the following, I am just getting an issue, a user, and assigning the issue to that user. 

Why is this not working?
It just keeps returning null without changing the assignee.

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()

def user = userManager.getUserByName("tbas")

def issueObject = issueManager.getIssueObject("HW_TEST-64")

issueObject.setAssignee(user)

 The logic makes sense, the method here says it should work aswell? See this.

But I don't kno why this aint working. 
Could anyone tell me? 

1 answer

1 accepted

Hi Tayyab,

There are two main issues here. The first one is that, whilst you are setting the Assignee on the object, there is no persistence happening. I have included an adjusted sample script to do what you want below:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()

def user = userManager.getUserByName("tbas")

def issue = issueManager.getIssueObject("HW_TEST-64")

def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
issueService.assign(user, validateAssignResult)

This script will perform the assignment you are looking for. There is a really good answer to this question by Jamie Echlin here Why can I not set assignee by ID Script Runner

I hope this helps!

Tayyab Bashir Community Champion Sep 08, 2017

Hi Stephen,

This works. I didn't even think about validation because the method didn't indicate anything like that. But this makes sense and helps a lot.

Thanks :)

Suggest an answer

Log in or Sign up to answer
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 Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

589 views 6 12
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