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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:DskTkt_CreateTicket"> <soapenv:Header> <urn:AuthenticationInfo> <urn:userName>${username}</urn:userName> <urn:password>${password}</urn:password> </urn:AuthenticationInfo> </soapenv:Header> <soapenv:Body> <urn:create> <urn:Area>Services</urn:Area> <urn:CaseType>Service Request</urn:CaseType> <urn:Description>test</urn:Description> <urn:GroupID>2000</urn:GroupID> <urn:GroupIDTxt>2000</urn:GroupIDTxt> </urn:create> </soapenv:Body> </soapenv:Envelope>""" if(fieldValue == customFieldValue) { try { def soapUrl = new URL("soapdomain/services/?webService=CreateTicket") def connection = soapUrl.openConnection() connection.setRequestMethod("POST") connection.setRequestProperty("Content-Type" ,"text/html") connection.setRequestProperty("SOAPAction", "") connection.doOutput = true Writer writer = new OutputStreamWriter(connection.outputStream) writer.write(soapRequest) writer.flush() writer.close() connection.connect() 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!
You have to write the listener as a class, did you do that? See chapter "Custom Groovy Listeners (for advanced users)" on https://jamieechlin.atlassian.net/wiki/display/GRV/Listeners
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 log.info 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>>>>> @Override void workflowEvent(Issue event) { log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by soapCall" } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to put your source (lines 5-53) into the method workflowEvent() after the log.debug call.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Some additional points:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.