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, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events