Hi all,
I'm trying to create a groovy script that runs on transition as a post function to take the author of the last comment and add them as the assignee of the issue. I have scriptrunner installed and am running JIRA server. I've written a script, which when run on transition, does not update the assignee when a comment exists, but also does not post any errors.
Any idea what I'm doing wrong? Thanks in advance!
---------
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.user.ApplicationUser
// get the latest comment
def commentauthor = ComponentAccessor.commentManager.getLastComment(issue)
// check to see if comments exist and return comment author
if (commentauthor != null) {
//return comment.authorFullName
commentauthor.authorFullName
}
return null
// turn author full name into a user name
def userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).includeActive(true).includeInactive(false).maxResults(100000).build();
def commentuserID = userSearchService.findUsers(commentauthor , userSearchParams) as ApplicationUser
//-------------------
//Assign the user to the issue
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
def validateAssignResult = issueService.validateAssign(commentuserID, issue.id, issue.reporterId)
issueService.assign(commentuserID, validateAssignResult)
You have to make issue update, after assignment.
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
p.s. your code is very complicated, it can be done easier
Try this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()
// get the latest comment
def lastComment = ComponentAccessor.commentManager.getLastComment(issue)
// check to see if comments exist and set assignee
if (lastComment != null) {
issue.setAssignee(lastComment.authorApplicationUser)
issueManager.updateIssue(user, issue, 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.