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.
Hi @Surendar Singh
You can look into the change history using ScriptRunner.
Take a look at this post here.
Ravi
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.CustomFieldimport com.atlassian.core.util.DateUtilsimport com.atlassian.jira.component.ComponentAccessorcom.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(); // nameString assigneeFullName = ci.getFromString();// full namedef assignedTime = ci.getCreated().getTime();firstAssigned = assignedTime;
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.IssueManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.link.IssueLinkimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.ApplicationUserIssueManager 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 firstNotNullAssigneeApplicationUser 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.
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.CustomFieldimport com.atlassian.core.util.DateUtilsimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.history.ChangeItemBeandef changeHistoryManager = ComponentAccessor.getChangeHistoryManager()def firstAssignee=changeHistoryManager.getChangeItemsForField(issue, "assignee")def firstNotNullAssignee = firstAssignee[0]?.from ?: firstAssignee[0]?.to//return assigneeissue.setAssigneeId(firstNotNullAssignee)
I am new to JIRA. Can you please suggest that where this piece of code will be written
It looks like you're new here. Sign in or register to get started.