Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,465,148
Community Members
 
Community Events
176
Community Groups

Automate a Jira Issue XML export - perhaps via a workflow transition

Hi

Would anyone have any suggestions on the best way to do this? I am attempting to replace a legacy ticketing system with Jira. The legacy system generated an XML per ticket that could be read by a media asset manager (MAM) and create a pre defined folder structure in the MAM based on the XML.

Could this be achieved in ScriptRunner during a workflow transition perhaps?

Thanks

Gordon

 

 

2 answers

1 accepted

0 votes
Answer accepted

I'm not familiar with the MAM or the XML structure, but sure... you could do that with scriptrunner.

As part of designing the code for this in the workflow post function, you would need to know all the Jira fields and custom fields that you want to map to the XML.

The best way to achieve that would be with the MarkupBuilder.

Something like this

import groovy.xml.MarkupBuilder
import com.atlassian.jira.component.ComponentAccessor
def customFields = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.mkp.xmlDeclaration(version:"1.0")
xml.root{
issuenode{
key{ xml.mkp.yield issue.key}
fields{
summary issue.summary
reporter issue.reporter.name
assignee issue.assignee.name
customFields.each{cf->
def val = cf.getValue(issue)
if(val){
"$cf.name"{xml.mkp.yield val}
}
}
}
}
}
writer.toString()

Will output an XML that looks like this

<?xml version='1.0'?> 
<root>
<issuenode>
<key>JSP-1922</key>
<fields>
<summary>blah blah</summary>
<reporter>xxx</reporter>
<assignee>xxx</assignee>
<My CustomField>the value</My CustomField>
<Another CF>value</Another CF>
<!-- etc for the rest of te custom fields -->
</fields>
</issuenode>
</root>

Obviously, you need to shape your code to output the right XML layout etc.

And then you need to decide what to do with that XML ... either store it to a local file or send it as an HTTP request to another system.

Hi Peter-Dave

Really appreciate your time and effort to suggest this answer! It will take me some time to test with a developer but will update you on progress.

Thanks again

Regards

Gordon

Hi @Peter-Dave Sheehan ,

I created an automation rule that composes raw xml  as content of an e-mail as well as I can send the xml via webrequest. Is it possible to store the xml as well automatically in a local file? How to do so?

Best regards

Karin

Hi Karin

I actually achieved it after input from Adaptavist and a web session Q&A.

This script will place a word document on the local machine Jira is running on.

It is running as part of a custom script post function

Hope this helps

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.TrustedRequest
import com.atlassian.sal.api.net.TrustedRequestFactory
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import groovyx.net.http.URIBuilder

@PluginModule
TrustedRequestFactory trustedRequestFactory

final issueKey = 'issue.key'
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issueKey)
assert issue

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def host = new URIBuilder(baseUrl).host
def xmlEndpointUrl = "/si/jira.issueviews:issue-xml/${issue.key}/${issue.key}.xml"

def request = trustedRequestFactory.createRequest(Request.MethodType.GET, "${baseUrl}$xmlEndpointUrl") as TrustedRequest
request.addTrustedTokenAuthentication(host, loggedInUser.username)
def result = request.execute()

log.warn result

new File("/tmp/${issue.key}.doc").withWriter { w ->
    w.write(result)
}

Suggest an answer

Log in or Sign up to answer