Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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 (https://library.adaptavist.com/entity/round-robin-assign-issue-to-users-in-a-certain-project-role), 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
import com.atlassian.jira.security.roles.ProjectRoleManager

// 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)
.applicationUsers
.toSorted { it.key }

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

if (!reassignedIssues && issue.assignee) {
log.info ('The issue is already assigned')
return
}

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

if (!lastIssueIdWithAssignee) {
issue.setAssignee(users.first())
return
}

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

issue.setAssignee(nextAssignee)

 

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(issue.projectObject.id)
.sort()
.reverse()
.find { issueManager.getIssueObject(it).assignee }

if (!lastIssueIdWithAssignee) {
issue.setAssignee(users.first())
return
}

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: https://community.atlassian.com/t5/Adaptavist-questions/Get-issue-id-of-last-created-issue-and-check-issue-type/qaq-p/1545522?utm_source=atlcomm&utm_medium=email&utm_campaign=mentions_answer&utm_content=topic#U1546501

 

I had to make the following changes to the script:

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Opsgenie

Opsgenie and Amazon team up to launch new DevOps Guru integration - now available!

We’re proud to announce that our integration with Amazon DevOps Guru is now live. The Amazon and Opsgenie product teams have worked together to build a deep integration between Opsgenie and the new...

238 views 0 6
Read article

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