Adding a custom listener with Script Runner

I'm attempting to create a custom listener using Script Runner, but I can't quite figure out how to get it configured. I hope if I clearly outline what I thought was the correct steps were to configure the custom listener, someone will find where I'm going wrong. My money is that it's something incredibly simple that goes to show my lack of programming experience. ;)

  • Create some super simple script and name it TaskVersionListener.groovy. (Script below.)
class TaskVersionListener extends AbstractIssueEventListener {
    Category log = Category.getInstance(TaskVersionListener.class)
 
    @Override
    void workflowEvent(IssueEvent event) {
        log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by TaskVersionListener"
    }
}
  • Place the non-compiled script in JIRA\atlassian-jira\WEB-INF\classes\com\custom.
  • Go to Admin then Listeners and add the listener you see below:

  • Go to Plugins > Other > Script Listener then to "Script Listeners" tab.
  • Click "Custom Listener"
  • Pick whatever appropriate events and projects.
  • Insert com.custom.TaskVersionListener as the Name of the groovy class.
  • Click Preview.

When doing so, i get the following error:

Not Found (404)

Could not execute action [CannedScriptListener]:Incompatible magic value 1668047219 in class file com/custom/TaskVersionListener<p><small><small><pre>java.lang.ClassFormatError: Incompatible magic value 1668047219 in class file com/custom/TaskVersionListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at

5 answers

1 accepted

This widget could not be displayed.

it seems a restart of the JIRA service did the trick. i'm not sure we'll ever know what was causing the misbehavior.

This widget could not be displayed.

Hrm yeah... I think you're mixing up the old and the new way of setting up custom script listeners. Been a while since I've looked at this myself but...

You don't need the Admin -> Listeners one you set up... although that method will probably work. But if you use that you need to click Edit and specify the path to the groovy file.

I've not seen that error about the magic file, it's like it's finding a a .groovy file when it expects a compiled class.

What version of the plugin and what of jira?

I'll go through this myself tomorrow and make sure the docs are up to date.

Hey, Jamie. Love the plugin and your work and thanks for the reply. To your answer:

  • I hope I was looking in the right place to understand what to do: https://studio.plugins.atlassian.com/wiki/display/GRV/Listeners
  • I was a bit confused by what I read in the custom groovy listener section and used some of the comments further down on the page to help guide me.
  • version of the plugin: 2.0.7
  • version of JIRA: 5.0.6
  • You say "it's like it's finding a .groovy file when it expects a compiled class." It *is* finding a groovy file. I never compiled that script you see above because I thought it was unnecessary to do so. Should it be compiled? (If so, I'll have to figure out how to do so.)

I'll keep an eye out for any further instructions. Thanks for the help.

jamie, i still haven't been able to identify what's going wrong for me here. any advice?

This widget could not be displayed.
Henning Tietgens Community Champion Sep 04, 2012

Do you have a

package com.custom

in your script?

Henning

good catch. i realized that was missing yesterday as well, added it, ran the same steps you see above, but .. alas .. i continue to get the same error that i posted above. any other ideas, henning?

Henning Tietgens Community Champion Sep 04, 2012

Mmh.. I tried this script in our instance and get the corresponding log messages:

package com.custom

import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Category

class TaskVersionListener extends AbstractIssueEventListener {
    Category log = Category.getInstance(TaskVersionListener.class)

    @Override
    void workflowEvent(IssueEvent event) {
        log.setLevel(org.apache.log4j.Level.DEBUG)
        log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by TaskVersionListener"
    }
}

If this is like your script, than I have no idea. It's exactly like I did it with my listeners...

Henning

This widget could not be displayed.
package com.custom  
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.crowd.embedded.api.User
import com.atlassian.event.api.EventListener
import com.atlassian.jira.util.ImportUtils
import org.apache.log4j.Category
  
class UpdateFieldComponent extends AbstractIssueEventListener {
    Category log = Category.getInstance(UpdateFieldComponent.class)
  
    UpdateFieldComponent () {
        log.setLevel(org.apache.log4j.Level.DEBUG)
    }
  
    @EventListener
    void workflowUpdated(IssueEvent event) {
        log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by UpdateFieldComponent"
         
        CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
         def cf=cfm.getCustomFieldObjectByName("Type of Request")        
         Option cfValue=(Option)issue.getCustomFieldValue(cf);
        if (cfValue.getValue().equals("G1 Block")) {       
            Project project = issue.getProjectObject()
            ProjectComponent component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(), "G1 Block")
            issue.setComponentObjects([component])
        } else {
            Project project = issue.getProjectObject()
            ProjectComponent component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(), "1 - Inbox")
            issue.setComponentObjects([component])
        }
        
    }
  
}

Hi,

I have added my listener to script runner, but it doesnt seem to do what I want it to. I.e update the components field when a custom field value is selected and Issue Updated event has been fired. Any ideas? Do I need to restart JIRA?

you'll probably get a better response if you open up another question. i think i know your answer, but i'll first wait for that new question before i answer. be sure to comment here with a link to it, and i'll reply.

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 yesterday 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...

65 views 1 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