Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Get issue id of last created issue of a certain issue type


Hi all,

One of the dev teams that I work with at my job want to utilize round robin assignment of users for a certain issue type. We have 4 listed users under the project role, "Workers", and for every Story issue that gets created in the project, the 4 users (person A [bmorris], person B [kbaker], person C [mkim], and person D [mlubag]) should be assigned in sequential order via round robin. Since the list of users is sorted by user key, the assignment goes from person A -> person D and again in that order infinitely.

In reference to this groovy script from Adaptavist Library (, I was able to use this script and render its use for our purpose by changing the value for final roleName to 'Workers':


import com.atlassian.jira.component.ComponentAccessor

// The role you want assignees to set from
final roleName = 'Workers'

// If it is true, the assigned issues will be reassigned
final reassignedIssues = true

def issueManager = ComponentAccessor.issueManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

// Get all of the users associated with the specified project role
def projectRole = projectRoleManager.getProjectRole(roleName)

// Sort the users of the project role using the user key
def users = projectRoleManager.getProjectRoleActors(projectRole, issue.projectObject)
.toSorted { it.key }

// There are no users in the specific project role
if (!users) { ("No users for project role $roleName")

if (!reassignedIssues && issue.assignee) { ('The issue is already assigned')

// Find the latest created issue id that has an assignee
def lastIssueIdWithAssignee = issueManager.getIssueIdsForProject(
.find { issueManager.getIssueObject(it).assignee }

if (!lastIssueIdWithAssignee) {

def lastAssignee = issueManager.getIssueObject(lastIssueIdWithAssignee).assignee
def lastAssigneeIndex = users.indexOf(lastAssignee)
def nextAssignee = users[(lastAssigneeIndex + 1) % users.size()]



This almost works the way I want it, but there's one problem...In the part of the script that pulls the most recently created issue that has an assignee: 

def lastIssueIdWithAssignee = issueManager.getIssueIdsForProject(
.find { issueManager.getIssueObject(it).assignee }

if (!lastIssueIdWithAssignee) {

This code seems to pull the most recently created issue, regardless of the issue type and whether or not it's assigned to anyone. We only want the round robin script to focus on issues of the issue type Story.

Is there a way in Groovy to get the most recently created issue (of a certain issue type) in a project?

P.S. I have this set as a post-function for the Create transition in a workflow specifically set for the Story issue type. I thought that would be enough, but it still looks at all the issues in the project, and not just stories.

Any help would be highly appreciated.

Thanks all!

-Ian Balas

1 answer

1 accepted

0 votes
Answer accepted

As per repost:


I had to make the following changes to the script:

def lastIssueIdWithAssignee = issueManager.getIssueIdsForProject(
.find {issue.getAsString("issuetype") == "Certification" }

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

147 views 0 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you