Forums

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

How set null value in fields type Double?

Alexander
Contributor
March 28, 2019

Hi Team!
Help me please for my problem :(

We need that fields calculated  ("stp","def_prod") and write sum in fields ("adm","total").

We have this script in behaviour plugin:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;

//Take fields by name

def stp = getFieldByName("cf1Name");
def adm = getFieldByName("cf2Name");
def total = getFieldByName("cf3Name");
def def_prod = getFieldByName("cf4Name");

//Take the value from the field and assign the type Double

def value_stp = stp.getValue() as Double
def value_def = def_prod.getValue() as Double


if (value_stp != null & value_def != null){
def sum_adm = (value_stp + value_def) * 0.15
adm.setFormValue(sum_adm)
total.setFormValue(value_stp + sum_adm)

}
else {
//Set null if value_stp\value_def = null

adm.setFormValue(null)
total.setFormValue(null)
}

Values are calculate. But after delete value fields ("stp", "def_prod") "adm" and "total" is not set null.
How cleaning Double field's value in Behaviour?

Thanks!

 

Best
Regards

1 answer

1 accepted

0 votes
Answer accepted
Alexander
Contributor
March 28, 2019

I found error in my script.
When i cleared my custom fields they have type "String".
When i write value they have type "Double".
Because of this condition "if" not work and value in customfield not cleared.

Below correcte script:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;

def stp = getFieldByName("cfName");
def adm = getFieldByName("cf2Name");
def total = getFieldByName("cf3Name");
def def_prod = getFieldByName("cf4Name");


if (stp.getValue() != "" && def_prod.getValue() != ""){
def sum_adm = ((stp.getValue() as Double) + (def_prod.getValue() as Double)) * 0.15

adm.setFormValue(sum_adm)
total.setFormValue((stp.getValue() as Double) + sum_adm)

}
else {
adm.setFormValue(null)
total.setFormValue(null)
}

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events