Forums

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

How to add custom field which takes output of, result of another custom field with division number

Kishore D
Contributor
March 9, 2022

Want to add one script field with below code. I am trying to achive division of custom filed with a number and output should store in my script field.

i have custom field A in my jira. Want to create Script field 'B'. B will store result of 'A'/1848.

Code:

import com.atlassian.jira.component.componentAccessor
import com.atlassian.jira.issue.Issue

def customFieldManager = componentAccessor.customFieldManager
def Benefits_EstCFID = 54700

def Benefits_EstCF = customFieldManager.getcustomFieldobject(Benefits_EstCFID)

if (!Benefits_EstCF) {
log.debug ("custom field with ID" + Benefits_EstCFID + "not found")
return null
}

def Benefits_Est = issue.getcustomFieldvalue(Benefits_EstCF)
return Benefits_Est/1848

Jira is giving result. But also failing the health condition on each execution at last line where i am dividing 'A' /1848

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
March 9, 2022

My guess is that the field is not of the type you are guessing it is, so Benefits_Est does not contain what you expect it to.

Kishore D
Contributor
March 9, 2022

Thanks for the reply.  Benefits_Est  is number type custom filed in our jira.
Script field which i am adding is also number type. 

Script field(number type) = Benefits_Est (number type)/1848.

This is  what i  want to work.


Kishore D
Contributor
March 10, 2022

After replacing line  ----> return Benefits_Est/1848 with 

return ((double)Benefits_Est)/1848 .

its working!!

Kishore D
Contributor
March 10, 2022

When i create  single jira issue for testing it worked. When i create multiple issues, it failing again. When we check logs, i see below

Logs:

[customfield.Groovycustomfield]: script field failed on issue: ABC-1675, field: Benefit_Est
org.codehaus.groovy.runtime.typehandling.GroovycastException: cannot cast object 'null' with class 'null' to class 'double'. Try 'java.lang.double' instead 
at script6.run(Script6.groovy:16)

Nic Brough -Adaptavist-
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.
March 10, 2022

I suspect the custom field you are reading from is empty

Kishore D
Contributor
March 10, 2022

calculation is happening and returning the division value in jira. But the problem is , Health condition is failing. it impacting server performance

Nic Brough -Adaptavist-
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.
March 10, 2022

I don't understand what you mean by "health condition"

Suggest an answer

Log in or Sign up to answer