Assign issue to last transtionion executor

Hey,
I'm trying to write script what will assign issue to last transition executor, script should be triggered by postfuncion in different transition. Code what I write below, unfortunately didn't works

 

for example 

from In progress to X (Transition from where I want to take value from ) and then from X to in porgress (Transition where script should be triger)

 

Jira version 7.3.6

SC 5.0.6

 

import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

MutableIssue issue = issue;
def userManager = ComponentAccessor.getUserManager();
Logger log = log;
log.setLevel(Level.INFO);

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeHistories = changeHistoryManager.getChangeHistories(issue)

def previousExecutors = changeHistories.collect {history ->;
    history.getChangeItemBeans().findResults {ChangeItemBean change ->;
        if (change.getField() == "assignee" && change.getField() == "In Progress" ) {
            return change.getFrom()
        }
    }
}.flatten()

def Name = changeHistoryManager.getChangeHistory(issue).get(row).getAuthorUser(); 
def NameOfPerson = userManager.getUserByName(previousExecutors)?.directoryUser;
issue.setAssignee(NameOfPerson);

Thanks in advice for all help and hint

 

1 answer

Wouldn't it be easier to store the user who does In Progress -> X in a custom field, and then read that field to set the assignee when doing X -> In progress? That's the approach i've used with a similar requirement before.

yep of course would be esier but right now I can't use new cusom field 

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 ...

2,760 views 11 18
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