Hi,
Initial requirement was when an issue is moved from source project to destination project need to copy value from Custom Field "Solution" in Source Project to "Comment" in destination project.
I wrote Groovy script for this "AddSolutionAsCommentListener.groovy" and placed this at following location: /home/jiranew/atlassian-jira-6.0.8-standalone/atlassian-jira/WEB-INF/classes/com/groovylistener/AddSolutionAsCommentListener.groovy
Then I added this class as Custom Listener on "Issue Moved" event for Source project -> then tried moving an issue from source project to destination project but couldn't find anything relevant in logs.
After that I added this class as Custom Listener on "Issue Created" event for Destination project -> then tried moving an issue from source project to destination project still couldn't find anything relevant in logs. Please help me.
Here is the code of Custom Listener:
package com.groovylistener
import org.apache.log4j.Category
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.JiraServiceContext
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.web.bean.PagerFilter
class AddSolutionAsCommentListenerTest extends AbstractIssueEventListener {
Category log = Category.getInstance(AddSolutionAsCommentListenerTest.class)
ComponentManager compManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = compManager.getCustomFieldManager()
def authenticationContext = compManager.getJiraAuthenticationContext()
JiraServiceContext ctx = new JiraServiceContextImpl(authenticationContext.getUser())
def searchProvider = compManager.getSearchProvider()
SearchRequestService searchRequestService = compManager.getSearchRequestService()
SearchRequest request = searchRequestService.getFilter(ctx,15702)
IssueManager issueManager = compManager.getIssueManager()
public AddSolutionAsCommentListenerTest()
{
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug statements"
log.info "in constructor"
}
@Override
void workflowEvent(IssueEvent event) {
MutableIssue issue = event.issue as MutableIssue
CommentManager commentMgr = compManager.getCommentManager()
commentMgr = (CommentManager) compManager.getComponentInstanceOfType(CommentManager.class)
sourceFieldName = "Solution"
CustomField customFieldSrc = customFieldManager.getCustomFieldObjectByName(sourceFieldName)
def results = getSearchResults(request)
results.getIssues().eachWithIndex { iss , i ->
issue = issueManager.getIssueObject(iss.id)
log.info "Processing ${issue.key}"
i += 1
String reporterUser = issue.getReporter();
def sourceFieldVal = "Solution -" + issue.getCustomFieldValue(customFieldSrc)
log.info "Actual Value of Solution: ${sourceFieldVal}"
log.info "Creating Comment"
commentMgr.create(issue, reporterUser, sourceFieldVal, false)
log.info "Added Comment"
}
}
SearchResults getSearchResults(SearchRequest sr) {
return searchProvider.search(sr.getQuery(), authenticationContext.getUser(), PagerFilter.getUnlimitedFilter())
}
}
Hi @Zahabiya Barbhaiwala,
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.