Forums

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

Difference between Two Custom DateTime Field using scripted field

Alvin
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.
September 30, 2018

Hi Community, I have a problem regarding with the datetime field . I am using two datetime custom field. I also use this scripted field by scriptrunner, but it returns an error

I used Date Time Range Picker as a Searcher and a Custom Template :

$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)

 

code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_10806');

def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_10807');

if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date
return dateValue - dateValue2
}

 

it says cannot return value of type int on method for java.util.Date. Thanks

1 answer

0 votes
Elifcan Cakmak
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.
October 1, 2018

Hello,

Your code returns the difference as days between two date fields. When you run the code it returns an integer. However your script field uses date time as a searcher. That's why your code cannot cast this number to your script field. If you change your script field's searcher to free text searcher or number searcher and template to text field or number field it should work just fine. 

Regards,

Elifcan

Suggest an answer

Log in or Sign up to answer