Hello,
I want to save the person who transition a ticket in a custom field but I need to do for our existing tickets...
How can I do with script console?
Thanks all for your help!
Hi,
That would be possible if source and target statuses are sufficient to identify the transition since you cannot retrieve the transition name in history manager.
Update the JQL request, user_key, sourceStatus and targetStatus (you can use id if needed).
Let me know if you need help updating the custom field.
import com.atlassian.jira.issue.history.ChangeItemBeanimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.web.bean.PagerFilter// Your jqljqlSearch = "key in (ABC-123, ABC-456)"SearchService searchService = ComponentAccessor.getComponent(SearchService.class)def userManager = ComponentAccessor.getUserManager()IssueManager issueManager = ComponentAccessor.getIssueManager()ApplicationUser user = userManager.getUserByKey('user_key')List<Issue> issues = nullSearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)if (parseResult.isValid()) { def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}} else { log.error("Invalid JQL: " + jqlSearch);}def changeHistoryManager = com.atlassian.jira.component.ComponentAccessor.getChangeHistoryManager()for (Issue issue:issues){ def ch = changeHistoryManager.getChangeHistories(issue) for(int i=ch.size() - 1; i >= 0; i--){ for (ChangeItemBean bean:ch.get(i).getChangeItemBeans()){ if (bean.getField() == "status" && bean.getFromString() == "sourceStatus" && bean.getToString() == "targetStatus"){ log.error("getAuthorDisplayName() : " + ch.get(i).getAuthorDisplayName()) log.error("getAuthorKey() : " + ch.get(i).getAuthorKey()) } } }}
ji @Antoine Berry ,
thank you for your answer. Just one question...I see an error in the code but I don't really know who to fix...in issues=searchResult.issues.collect {issueManager.getIssueObject(it.id)}
has this error: [static type checking] - incompatible generic argument types. Cannot assign java.util.List <com.atlassian.jira.issue.MutableIssue> to: java.util.List<issue>
you know how to fix it?
so thank you!
I tried this code and it has been working fine. Are you getting the error when you run the code or is it highlighting in the script console ?
Highligh in the script console. But I try without modify anything in the code but dont return anything in logs....
It looks like you're new here. Sign in or register to get started.