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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,345 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot