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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

112 views 2 0
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