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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

207 views 3 0
Join discussion

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