Referencing the round robin assignment script from adaptavist library:https://library.adaptavist.com/entity/round-robin-assign-issue-to-users-in-a-certain-project-role, I want to get the last issue created in a project, but i also want to focus in on a certain issue type.
Here's what I changed in the script:
def lastIssueIdWithAssignee = issueManager.getIssueIdsForProject(issue.projectObject.id)
.sort()
.reverse()
.find {issue.getAsString("issuetype") == "Certification" }
So with this, I thought I'd be able to find the last Certification issue created in that project, but this doesn't seem to be the case...because the assignee keeps defaulting to the first user listed in the user key array.
Is there anything wrong with the change I made to the script?
Hi @Nour Durra _ Consultant , Just saw your request yesterday, worked on it and it was possible. It was a bit tough, so it was interesting. Hope this would help..!
Create a custom listener like shown in the image.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
def issue = event.getIssue() as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10488")
def cFieldValue = issue.getCustomFieldValue(cField)
String userName
switch(cFieldValue){
case "Q1": userName = "kevin.e";break;
case "Q2 ": userName = "angelinjebapriya";break;
case "Q3": userName = "kevin.e";break;
case "Q4": userName = "angelinjebapriya";break;
case "Sales Team": userName = "kevin.e";break;
default: userName = null;
}
UserManager userManager = ComponentAccessor.getUserManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser assignToUser = userManager.getUserByName(userName)
// Get a list of the current issue's subtasks
def subtasks = issue.getSubTaskObjects()
// Loop through all the subtasks and delete them
subtasks.each{it->
if(cField) {
def changeHolder = new DefaultIssueChangeHolder()
def i = it as MutableIssue
log.error(assignToUser)
log.error(cFieldValue)
log.error(i)
//update same custom field value in subtasks
cField.updateValue(null, it, new ModifiedValue(issue.getCustomFieldValue(cField), cFieldValue),changeHolder)
//set assignee as desired
i.setAssignee(assignToUser)
issueManager.updateIssue(assignToUser, i, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.