Forums

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

Next-Gen Jira Project Calculated Field

tmy July 15, 2019

Hi,

I have two number fields A and B.

I want to create a custom field C which does a simple calculation (e.g. value(C) = value(A) / value(B), rounded to one decimal).

How can I do that in a next-gen Jira project?

Thanks!

2 answers

1 accepted

1 vote
Answer accepted
tmy July 15, 2019

I solved this problem now by using the ScriptRunner plugin (App found in Atlassian Marketplace) where I setup an event listener on an 'issue update' event.

Here's my script code, maybe this helps others:

// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>

def input1CfId = customFields.find { it.name == 'Source field 2 title' }?.id
def input2CfId = customFields.find { it.name == 'Source field 1 title' }?.id
def outputCfId = customFields.find { it.name == 'Target field title' }?.id
def projectKey = "<your project key>"

if (issue == null || ((Map)issue.fields.project).key != projectKey) {
logger.info("Wrong Project \${issue.fields.project.key}")
return
}

def input1 = issue.fields[input1CfId] as Integer
def input2 = issue.fields[input2CfId] as Integer

if (input1 == null || input2 == null) {
logger.info("Calculation using \${input1} and \${input2} was not possible")
return
}

// Calculation for target field
def output = input1 / input2

if (output == (issue.fields[outputCfId] as Integer)) {
logger.info("already been updated")
return
}

put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()
1 vote
David Gardner
Contributor
July 15, 2019

I am afraid this might be quite hard in Jira cloud and next-gen projects. They are designed to be simple and do not support this type of requirement. Some of the popular scripted custom field plugins will support this but mainly for the server versions. Atlassian do not open their API for different custom field types like this in the cloud. So lots more options on the server version but fairly sure that even classic projects in Jira cloud will not do this. Are you sure you want to use next-gen projects they are almost too simple? Have a read of this as if you want to migrate to classic projects later you will have to more all the issues by hand and could lose data.

https://confluence.atlassian.com/jirasoftwarecloud/migrate-between-next-gen-and-classic-projects-957974933.html

tmy July 15, 2019

Thanks David for your input.

I solved this problem now by using the ScriptRunner plugin (App found in Atlassian Marketplace) where I setup an event listener on an 'issue update' event.

See my other answer for details.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events