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)