Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to put zero value if a custom field is null

I'm using Jira software and the Secure Fields plugin. Three custom fields to do a simple calculation: the budget that remains when you subtract the spent budget from the initial budget.

My code is this, and it's embedded in a Script Runner behavior.

Since I've noticed that if by mistake a value in the custom field is deleted, it takes the value "null", this means that the custom field is no longer shown in the screen and above all it happens that it is not considered in my code that in fact no longer does the subtraction.

How can I do, I ask for help, to make it so that it runs a control like: if the customfield is equal to "null" then value it to "zero"?
So that after that the subtraction can be performed correctly ?

 

Double totalBudget = Double.valueOf(""+getFieldById("customfield_12101").getValue())
Double spentBudget = Double.valueOf(""+getFieldById("customfield_12400").getValue())

def remainingBudget = totalBudget - spentBudget;

getFieldById("customfield_12402").setFormValue(remainingBudget)

 

2 answers

Heya @Kalos Bonasia 

I'm not too familiar with Secure Fields and how they would interact with ScriptRunner, but would something like this help?

if (remainingBudget == null)
{getFieldById("customfield_12402").setFormValue("0")}
else
{getFieldById("customfield_12402").setFormValue(remainingBudget)}

I'm not quite sure what custom field type 12402 is, but hope this might work as a potential workaround.

Hi @Kalos Bonasia  there could be simple fix but Code seems quite complicated to me. What is the type of custom fields

  • customfield_12101
  • customfield_12400

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.1
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - Spring 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

89 views 1 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you