I have an xml response from web service and need to parse it to set some details of this response (values of ErrCode and ErrMsg elements) to the comments of the issue. All this must be done from the Custom-script postfunction. This is what i've done:
import groovy.xml.* import groovy.util.XmlSlurper def xml = ''' <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <SMSGateWayResponse xmlns="http://xxxx"> <SMSGateWayResult xmlns:a="http://xxxx" xmlns:i="xxxxx"> <a:ErrCode>OK</a:ErrCode> <a:ErrMsg>OK</a:ErrMsg> </SMSGateWayResult> </SMSGateWayResponse> </s:Body> </s:Envelope> ''' def xmlresult = new XmlSlurper().parseText(xml) //want to do something like this def res = xmlresult.Body.SMSGateWayResponse.SMSGateWayResult.ErrMsg.text()
and this res result is added to the comment
commentManager.create( issue, user, "response: $res", false)
But console returns me error No such property: SMSGateWayResponse for class: groovy.util.slurpersupport.GPathResult.
This is not working, too.
Do you need to use SOAP? It's not very user friendly. If you're using some system for SMS sending I'm sure it has a REST API.
I don't see where you're actually executing the request to the remote system, or is this just test code?
For XML with namespaces you have to do some more stuff - see http://stackoverflow.com/questions/8669766/namespace-handling-in-groovys-xmlslurper.
Thanks, I've found this a day ago and now the script works.
This xml is the response of our web service, I've used it as a test case to see how it can be parsed.
def xmlresult = new XmlSlurper().parseText(xml) assert xmlresult instanceof groovy.util.slurpersupport.GPathResult def res = xmlresult.Body //return res in Script console or adding a comment in workflow post function
Result.Body returns me OKOK (ErrCode and ErrMsg). Dont know how to separate them.
If I try to go deeply into the xml tree ( xmlresult.Body.SMSGateWayResponse ) the system returns that there is not such property.
Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...
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!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG