Updating assignee via scriptrunner

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

Accepted Answer
1 vote

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!

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
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

421 views 7 5
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