Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Customfield which calculated out of 2 other customfield Edited

Hi guys,

I want a customfield which calculates the next revision. 

I want to use the value of a customfield "months" (contains a numerical value for the number of months) and add up the value of the "release date" (also a customfield).

The result should then be displayed in the new custom field "Next revision".

So the release date is already a date format. 
The months field is only a numerical value. 

Thanks for your help!

Best Regards 
Tobias 

1 answer

0 votes

There's a scripted field that almost does what you want over at https://library.adaptavist.com/entity/calculate-the-difference-between-two-dates - shouldn't be too hard to convert from "calculate difference" to add X months to a base date and return it"

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import java.sql.Date
import java.sql.Timestamp
import com.atlassian.jira.issue.Issue;

def cfIntervall = ComponentAccessor.customFieldManager.getCustomFieldObject(13022)
def cfFaelligkeit = ComponentAccessor.customFieldManager.getCustomFieldObject(15024)

if (cfIntervall && cfFaelligkeit && issue.getCustomFieldValue(cfIntervall) && issue.getCustomFieldValue(cfFaelligkeit))
{
def intMonth = issue.getCustomFieldValue(cfIntervall) as Integer;
return intMonth;
def newDate=issue.getCustomFieldValue(cfFaelligkeit)+intMonth;
}
else
{
return null;
}

Hi @Nic Brough _Adaptavist_  
this was my first idea, but my problem is that i can't extract the date out of the cfFaelligkeit date picker customfield. This is my current problem...As a result i should receive a date format.

Ok, there's a couple of problems here:

def intMonth = issue.getCustomFieldValue(cfIntervall) as Integer;
return intMonth;

This will exit the script, returning simply that month number.  It's never reading the second custom field, let alone doing anything with it.

def newDate=issue.getCustomFieldValue(cfFaelligkeit)+intMonth; 

Here, you've not looked at what the field contains.  It's not a number of months, it's a timestamp.  The script can compile this ok because it is possible to ask a timestamp for a number, but the number you'll be getting is not months, as you haven't asked it for months.

Have a look at https://docs.oracle.com/javase/8/docs/api/java/sql/Timestamp.html for working with timestamps

Suggest an answer

Log in or Sign up to answer
TAGS

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