Forums

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

Scriptrunner for structure to evaluate custom field content using scripts

Andreas Halbig April 15, 2022

Hi guys,

we have the SCriptrunner extension within our JIRa (non-cloud version). Our project as a very weird way to manage the work load of stories. Here is one example

We have an Story, which has 10 Story-Points estimated. Normally you would expect that you create Sub-Tasks for each individual person/resource you need with an corresponding time estimate. Instead we have on the Story an custom field which holds the list of tagged people in Jira with the individual work-load share e.g. "@tom 2, @peter 4, @nurac 4". Our program team us now using those values to make their capacity plannung within a excel sheet using the corresponding story point work-load of each individual person.

I can not change that strange way and i dont have budget to buy more extension, but i wanna improve that process. I want JIRA to tell me, how many Story-Points of Stories within a certain sprint are covered by an specific person. Is there an way to evaluate such custom field and transfer those calculations into an e.g. Structure ?

I want in the end something like

Sprint A

User   | Story 1 | Story 1 | Total

################
Tom  | 2            | 6           | 8
Peter | 4           | 0            | 4
Alex  | 4            | 1            | 5
##################
Sum  | 10          | 7           | 17

Sprint B

[Another table like above]

 Have you any suggestions ?

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2022

I don't think you can do that with ALM Structure (if that's what you meant).

But you might be able to do it with a random WebPanel. 
Not sure where the best place to display that panel might be, however.

And I made an assumption that your custom field actually contains data (on a single line) like:

"[~tom] 2, [~peter] 4, etc" 

Where [~tom] is the wikimarkup that results in @[deleted] in the rich text view.

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import groovy.xml.MarkupBuilder

def jql = "YOUR JQL QUERY HERE"
def taskDetailsCustomFieldId = 123456 //YOUR FIELD ID HERE

SearchService searchService = ComponentAccessor.getComponent(SearchService)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def taskDetailsCf = ComponentAccessor.customFieldManager.getCustomFieldObject(taskDetailsCustomFieldId )
def sprintCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Sprint')[0]


def
parseResult = searchService.parseQuery(currentUser, jql)
assert parseResult.isValid() : parseResult.errors

def resultMap = [:]

searchService.search(currentUser,parseResult.query, PagerFilter.unlimitedFilter).results.take(10).each{issue->
def sprints = issue.getCustomFieldValue(sprintCf)
if(!sprints) return null
def sprintName = sprints.last().name
if(!resultMap.containsKey(sprintName)){
resultMap[sprintName] = [:]
}
def taskDetailsVal = issue.getCustomFieldValue(taskDetailsCf) as String
taskDetailsVal.tokenize(',').each{
def pattern = /\[~(.*?)\] (\d*)/
def matcher = it =~ pattern
def user = matcher[0][1]
def sp = matcher[0][2] as Integer
if(!resultMap[sprintName].containsKey(user)){
resultMap[sprintName][user] = [:]
}
resultMap[sprintName][user][issue.key] =sp
}
}

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
resultMap.each{String sprintName, Map userMap->
def stories = userMap.collect{it.value.keySet()}.flatten().unique()
builder.h2 sprintName
builder.table{
thead{
tr{
td "User"
stories.each{
td it
}
td "Total"
}
}
tbody{
def storyTotals = [:]
userMap.each{String user, Map storyMap->
tr{
td user
td stories.sum{
def sp =storyMap[it] ?: 0
td sp
storyTotals[it] = (storyTotals[it] ?: 0)+sp
sp
}
}
}
tr {
td 'Sum'
td stories.sum {
def sumStory = storyTotals[it] ?: 0

td sumStory
sumStory
}
}
}
}
builder.br{}
}
writer.toString()

You can run that code in the groovy console to sample the results.

Suggest an answer

Log in or Sign up to answer