Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Change assignee when issue moves (Script runner)

Māris Freimanis February 26, 2019

Hello.

I'm trying to figure out, how using script listener, change existing assignee to moved project def. project lead.

Like - now it's in "Project 1" and I need to move it to "Project 2". I need to change assignee to "Project 2 " Project Lead.

Any ideas how to do it?

1 answer

1 accepted

0 votes
Answer accepted
Tarun Sapra
Community Champion
February 26, 2019

Hello @Māris Freimanis 

Add a custom listener which is listening to issue move events and in that listener you can write the code to update the assignee.

Māris Freimanis February 26, 2019

@Tarun Sapra I have done it that far. But I'm not that good at coding yet. Can't figure out how to do it. Tricky part is to restrict it that auto assign to project lead happens only, if I move from Project A to project B, but not happen if I move project A to project C or B to A. 

Tarun Sapra
Community Champion
February 26, 2019

You can get the project lead user name and then update the issue with issueManager

def userName = issue.getProjectObject().getLeadUserName()

The use the code sample from below to update/edit an existing issue

https://developer.atlassian.com/server/jira/platform/performing-issue-operations/

Māris Freimanis February 26, 2019

@Tarun Sapra 

Thanks. that actually helped me a lot.

So I have got this far. It assign pretty well now.

Only question is, is there a way, to use this only if there is transition from, like project A to project B? But it's not working when move from project C to B.

If I put Project B in Project Key then it works also if I move from project C to B. But I want to make it only when it's moved from A to B.

My code so far:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;

def issue = ComponentAccessor.getIssueManager().getIssueObject(event.getIssue().getId());

if (issue.getAssignee() == null) {
def userName = issue.getProjectObject().getLeadUserName();
issue.setAssigneeId(userName);
}

ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false);

SLIUser
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 20, 2020

@Tarun Sapra this is your final code? I have a similar case where I what to change the  Assignee (projectLead in my case when a issueMoved in a Listener) but no solution, found do this action. Can you help me? tks

Suggest an answer

Log in or Sign up to answer