Forums

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

Need to be able to convert a date comparison to a number value

Joe Harmon
Contributor
January 31, 2020 edited

I am not sure that where I am going wrong on this is in the date section.  I am trying to create a formula that will return a value based on the following formula.

Priority = (revenue/365)/(goal date - today)

Here is what I have but I am getting an error when the formula tries to calculate.

revenue = issue.get("Incremental Revenue")
days = 365
goal = issue.get("Goal Date")
today = new Date().format("yyyy-MM-dd")
if (revenue == null) return null;
if (revenue == 0) return 0;
if (goal == null) return null;
return (revenue/days)/(goal-today)

I am using a jira calculated field from JMCF 

2 answers

1 accepted

0 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2020

The problem stems from the fact that you are converting "today" into a String. It should be a Date, just like "goal". In that case, the "-" operator between two Date objects will return the difference in number of days.

Also, I'm not sure what you're calculating, but don't you want to multiply by the number of days between now and the goal date instead of dividing?

def revenue = issue.get("Incremental Revenue")
def days = 365
def goal = issue.get("Goal Date")
def today = new Date()
if (revenue == null) return null;
if (revenue == 0) return 0;
if (goal == null) return null;
return (revenue/days)/(goal-today)
Joe Harmon
Contributor
January 31, 2020

That worked thanks.  Is there a way to have the output not include anything after the decimal?

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2020 edited

Two ways, depending on whether you want the value to retain the decimals (just not display them) or round up the value itself:

- use a Number Formatting script like:

numberTool.format(Math.round(value))

- round the value in the formula:

return Math.round((revenue/days)/(goal-today))
Joe Harmon
Contributor
January 31, 2020

thank you

Joe Harmon
Contributor
January 31, 2020

The second example with the Math.round on the return didn't seem to work.  I'll try the formatting option, but I would rather have the actual result work as I am sure we will be exporting some of this data to confluence, where the formatting doesn't seem to work.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2020

Sorry, that was such a stupid answer on my part that I actually edited it out 😊

See the updated answer.

Joe Harmon
Contributor
January 31, 2020

Thanks again.

0 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2020

Are you using JMCF 1.7 or 2.x?

Joe Harmon
Contributor
January 31, 2020

2.1.6

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events