Custom Listener not getting invoked


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.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.debug "debug statements" "in constructor"
   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(
 "Processing ${issue.key}"
        i += 1
        String reporterUser = issue.getReporter();
        def sourceFieldVal = "Solution -"  + issue.getCustomFieldValue(customFieldSrc)
     "Actual Value of Solution: ${sourceFieldVal}"
 "Creating Comment"
        commentMgr.create(issue, reporterUser, sourceFieldVal, false)
 "Added Comment"

   SearchResults getSearchResults(SearchRequest sr) {
       return, authenticationContext.getUser(), PagerFilter.getUnlimitedFilter())

1 answer

Hi @Zahabiya Barbhaiwala,

  1. Just to be sure, add an log.error in your constructor, this will be shown if the cosntructor is called
  2. Remove your custom code and just log the event incomming, to make sure you don't have problems with your code
  3. Does the script work if you run it via the console?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,152 views 5 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you