Forums

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

How to get a completion percentage of a Story

Edimara Souza
Contributor
March 4, 2021

I need to create a custom field that shows the completion percentage of a Story. For example, if an story have 4 sub-tasks and one of them are "done" this field must show 25%
But I am have some difficulties with this script:

 

Can someone help me with this? What's wrong?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import java.text.DecimalFormat
import java.text.NumberFormat

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
DecimalFormat df = (DecimalFormat)nf
df.applyPattern("###,##0.00")

// edit this query to suit
def query = jqlQueryParser.parseQuery("issueFunction in subtasksOf(\"issuekey=" + issue.key + "\",\"is children of\")")
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

log.debug("Total issues: ${search.total}")

def Progresso = 0
def StatusFinalizado = 0
def Total = 0
def textoCategoria = ""

search.results.each { documentIssue ->
log.debug(documentIssue.key)

// if you need a mutable issue you can do:
def issueJira = issueManager.getIssueObject(documentIssue.id)

//ajuste para não entrar os itens removed
if (!issueJira.issueType.isSubTask() && issueJira.issueType.name != "Story" && issueJira.getStatus().name != "Removed")
{

/// textoCategoria = textoCategoria + " - " + issueJira.issueType.name

if(issueJira.getStatus().getStatusCategory().name == "Complete" && issueJira.getStatus().name != "Removed" ) {
(StatusFinalizado++)
textoCategoria = textoCategoria + " - " + issueJira.issueType.name
}

(Total++ )
}
}

if (Total > 0){
//Total de Features em Andamento ou finalizado
Progresso = (((int)StatusFinalizado) / (int)Total) * 100;
}

//return (int)StatusFinalizado

return df.format(Progresso) + "%"

//StatusFinalizado

 

1 answer

1 accepted

1 vote
Answer accepted
Edimara Souza
Contributor
March 4, 2021

..

Suggest an answer

Log in or Sign up to answer