Issue update scriptrunner script works in console not with listener

Hey guys,

I have a script that is supposed to make a SOAP call to a different application when a ticket is updated and contains a certain value. Here is basically my script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

String username = "username"
String password = "password"

//ID's for custom field and value
String customFieldId = "customfield_11300"
String customFieldValue = "[value1]"

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
String fieldValue = issue.getCustomFieldValue(customField);

def soapRequest = """<soapenv:Envelope xmlns:soapenv="" xmlns:urn="urn:DskTkt_CreateTicket">
         <urn:CaseType>Service Request</urn:CaseType>

if(fieldValue == customFieldValue) {
   try {
      def soapUrl = new URL("soapdomain/services/?webService=CreateTicket")
      def connection = soapUrl.openConnection()
      connection.setRequestProperty("Content-Type" ,"text/html")
      connection.setRequestProperty("SOAPAction", "")
      connection.doOutput = true

      Writer writer = new OutputStreamWriter(connection.outputStream)

      def soapResponse = connection.content.text
      def Envelope = new XmlSlurper().parseText(soapResponse)

   } catch (Exception e) {}

If I post this into the script console it works great. I can go into the other application and see that it worked. I then went to setup the listener with 'Issue Update' and it doesn't work. I've modified the JIRA ticket several times selecting that custom field value with no luck. Am I missing something? Thanks for any help!

1 answer

1 accepted

0 votes
Accepted answer
Henning Tietgens Community Champion Feb 20, 2014

You have to write the listener as a class, did you do that? See chapter "Custom Groovy Listeners (for advanced users)" on

If this doesn't help, I would suggest to add log messages to see where the problem is.

log.error "message"

will log the message as ERROR to your log files. If you want to use or log.debug make sure the log level is set to the corresponding value.

Ok, this is all new to me. I currently have the file in classes/custom/listeners/soapCall.groovy. So I modified the script to be a class (it was not before hand).

After making these changes I went to re-add the listener and got this error:
Problem loading class: startup failed: /opt/atlassian/jira/atlassian-jira/WEB-INF/classes/custom/listeners/soapCall.groovy: 57: unexpected token: if @ line 57, column 4. if(fieldValue == customFieldValue) { ^ 1 error

At this point I'm wondering if I have been staring at the code too long. I don't see why I am getting that.

Henning Tietgens Community Champion Feb 23, 2014

Could you post the script? Otherwise it's very difficult to analyse the error. The error message says there is an "if" on a place where it's not expected. Did you close all brackets and strings?

It will only let me comment 2000 characters, so:

package custom.listeners

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEvent;
import org.apache.log4j.Category

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

<<<<<lines 5-53 from initial post>>>>>

   void workflowEvent(Issue event) {
      log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by soapCall"

Henning Tietgens Community Champion Feb 23, 2014

You have to put your source (lines 5-53) into the method workflowEvent() after the log.debug call.

Henning Tietgens Community Champion Feb 23, 2014

Some additional points:

  • add import com.atlassian.jira.event.issue.AbstractIssueEventListener
  • change type Issue to IssueEvent for first parameter of workflowEvent()
  • change
    String fieldValue = issue.getCustomFieldValue(customField)
    String fieldValue = event.issue.getCustomFieldValue(customField)

Thanks! That appears to have done the trick!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,676 views 18 21
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