I have a script in ScriptRunner which works for me but assigns users randomly
import org.slf4j.LoggerFactory
import java.time.DayOfWeek
import java.time.LocalDate
import java.util.Random
def logger = LoggerFactory.getLogger(this.class)
def today = LocalDate.now().dayOfWeek
def assigneeAccountIds = getAssigneeAccountIdsForDay(today)
if (assigneeAccountIds) {
def randomIndex = (new Random() as Random).nextInt((assigneeAccountIds as List).size())
def assigneeAccountId = (assigneeAccountIds as List).get(randomIndex)
def updateResponse = put("/rest/api/3/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields: [
assignee: [
accountId: assigneeAccountId
]
]
])
.asString()
logger.info("Ticket ${issue.key} asignado al usuario con accountId: ${assigneeAccountId}")
} else {
logger.warn("No hay una tarea especificada para el dia: ${today}")
}
def getAssigneeAccountIdsForDay(DayOfWeek dayOfWeek) {
switch (dayOfWeek) {
case DayOfWeek.MONDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.TUESDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.WEDNESDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.THURSDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.FRIDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.SATURDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.SUNDAY:
return ["ID1","ID2","ID3"]
default:
return []
}
}
But I need to assign the users uniformly, currently in a random way there are users who have 10 tickers and another 2 tickets
I made this change, but instead of splitting the assignment it just assigns me to the same user
Do they know of a way to assign users evenly so that one user does not have 10 tickets and another 2?
import org.slf4j.LoggerFactory
import java.time.DayOfWeek
import java.time.LocalDate
def logger = LoggerFactory.getLogger(this.class)
def today = LocalDate.now().dayOfWeek
def counter = 0
def assigneeAccountIds = getAssigneeAccountIdsForDay(today)
if (assigneeAccountIds) {
def nextIndex = (counter++ % (assigneeAccountIds as List).size())
def assigneeAccountId = (assigneeAccountIds as List)[nextIndex]
def updateResponse = put("/rest/api/3/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields: [
assignee: [
accountId: assigneeAccountId
]
]
])
.asString()
logger.info("Ticket ${issue.key} asignado al usuario con accountId: ${assigneeAccountId}")
} else {
logger.warn("No hay una tarea especificada para el día: ${today}")
}
def getAssigneeAccountIdsForDay(DayOfWeek dayOfWeek) {
switch (dayOfWeek) {
case DayOfWeek.MONDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.TUESDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.WEDNESDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.THURSDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.FRIDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.SATURDAY:
return ["ID1","ID2","ID3"]
case DayOfWeek.SUNDAY:
return ["ID1","ID2","ID3"]
default:
return []
}
}
I use this in "Script Listeners" with the Issue Create event
Hi Marcelo,
To be able to assign user issues in an even manner, you would need to make sure you assign the issue to the next element in the array of user IDs each time.
One way to do this would be to use a project property inside of Jira cloud, as you could then update this each time an issue is assigned with the element number from the array for the user it was assigned to.
This means each time the script is run, it could start off by getting this value out and incrementing it by 1 to always get the correct value.
I can confirm I have some example code here which can be run on the script console which shows how to get and set a project property, and you can use it as a guide to help with this requirement.
Note the first time the project property is updated it will be created, so you can run just this code to create it before you run your script with this logic in.
I hope this information helps.
Regards,
Kristian
Could you share the example with me, since I do not have the permissions on the link. Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marcello,
Sorry for the permissions issue.
You should now be able to see the code publically on the link at https://bitbucket.org/Adaptavist/workspace/snippets/7qXyxX
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.