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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.