I need to get first assignee (when a task is assigned by project lead and when it is rejected by QA team, it must auto-assign to the first assignee of the task ),I am using scriptrunner by using script but i am not able to get value.
Hello Ravi,
I appreciate for your answer, but code is not in deprecated and getting issue.
i am attaching my code please provide solution.
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
com.atlassian.jira.issue.changehistory.ChangeHistoryManager
def componentAccessor = ComponentAccessor.getInstance();
def changeHistoryManager = componentAccessor.getChangeHistoryManager();
def changeItems = changeHistoryManager.getChangeHistories(issue);
return changeItems.get(changeItems.size()-1).getAuthorObject()
def firstAssigned;
if(changeItems !=null && !changeItems.isEmpty()){
ChangeItemBean ci = (ChangeItemBean) changeItems.get(0);
String assigneeName = ci.getFrom(); // name
String assigneeFullName = ci.getFromString();// full name
def assignedTime = ci.getCreated().getTime();
firstAssigned = assignedTime;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please try the code below. It will first retrieve the first assignee of the issue and then assign the issue to that first assignee.
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject("ANDROID-41");
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def firstAssignee=changeHistoryManager.getChangeItemsForField(issue, "assignee")
def firstNotNullAssignee = firstAssignee[0]?.from ?: firstAssignee[0]?.to
//return firstNotNullAssignee
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(firstNotNullAssignee.toString())
def issueService = ComponentAccessor.getIssueService()
def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
issueService.assign(user, validateAssignResult)
Please note: I have not included all the checks in the code like what will happen if there is no assignee of the issue or if user doesn't exist anymore but I hope this code will give you good starting point.
Thanks. Let me know if it helps.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Ravi
It worked for me and i have made some changes and code is working now. I am attaching my code here:
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def firstAssignee=changeHistoryManager.getChangeItemsForField(issue, "assignee")
def firstNotNullAssignee = firstAssignee[0]?.from ?: firstAssignee[0]?.to
//return assignee
issue.setAssigneeId(firstNotNullAssignee)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Ravi
It worked for me and i have made some changes and code is working now. I am attaching my code here:
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def firstAssignee=changeHistoryManager.getChangeItemsForField(issue, "assignee")
def firstNotNullAssignee = firstAssignee[0]?.from ?: firstAssignee[0]?.to
//return assignee
issue.setAssigneeId(firstNotNullAssignee)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good to know that :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am new to JIRA. Can you please suggest that where this piece of code will be written
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.