Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add order by ASC or DSC in my groovy script?

Shahriar April 10, 2020

Hi folks, 

I have a groovy script that works great for me and gives me what I need. I am trying to make a little change though. It displays a table for me with all the data but I need it in ASC order of the "Product Portfolio" column. Below are the full script and I am also attaching a screenshot of how the table looks like. Any help would be really appreciated. I hope everyone is staying safe during this crazy pandemic time. 

 

Thanks, 

Shahriar

Screen Shot 2020-04-10 at 11.52.28 AM.png

--------start script -------

import com.atlassian.jira.component.ComponentAccessor
import groovy.xml.MarkupBuilder

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def links = issueLinkManager.getOutwardLinks(issue.id)

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)


if(!links){
return null
}

xml.style(type:"text/css",
'''
#scriptField, #scriptField *{
border: 1px solid black;
}

#scriptField{
border-collapse: collapse;
}
''')

xml.table(id:"scriptField"){

tr{
th( "Key")
th("Summary")
th("Status")
th("Product Portfolio")
th("Target Delivery Date")
th("Fiscal Year")
th("Quarter")

}

links.each {issueLink ->

def productPortfolio = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(15327)
def targetDeliveryDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(15103)
def fiscalYear = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(14402)
def quarter = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(15326)
def keyInvestmentArea = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(15718)
def additionalCategory = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(15851)
def productOwner = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10000)

def linkedIssue = issueLink.destinationObject
if (linkedIssue.issueType.name == "Epic")
tr{
td(linkedIssue.key.toString())
td(linkedIssue.summary.toString())
td(linkedIssue.status.getName().toString())
td(linkedIssue.getCustomFieldValue(productPortfolio))
td(linkedIssue.getCustomFieldValue(targetDeliveryDate))
td(linkedIssue.getCustomFieldValue(fiscalYear))
td(linkedIssue.getCustomFieldValue(quarter))

}
}
}

return (writer.toString())

 

-------end script-----

1 answer

0 votes
Matt Doar
Community Champion
April 10, 2020

Sorting by that custom field would need to be done in the JQL that finds your issues. The script you show is processing each issue

Shahriar April 10, 2020

Hi Matt, 

Thanks for your response. 
What should I change in my script to sort the data by that field? 
You mentioned that it needs to be done in the JQL, how and where exactly? 

 

Thanks, 

Shahriar

Suggest an answer

Log in or Sign up to answer