Forums

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

Customfield which calculated out of 2 other customfield

Tobias
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 11, 2021

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
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 11, 2021

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"

Tobias
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2021
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.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2021

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