I have the following scripted field. It is returning a value but it isn't the correct value. See code below and example.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObjectByName('Restored Date/Time');
def dateFieldObject2= customFieldManager.getCustomFieldObjectByName('Incident Start Date/Time');
if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2))
{
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date
return dateValue.getTime() - dateValue2.getTime()
}
EXAMPLE FROM TOOL: ((note MTRS is my scripted field))
Incident Start Date/Time: 2019-01-25 1:51
Restored Date/Time: 2019-01-25 04:52
MTRS: 17 weeks, 6 days, 16 hours, 40 minutes
The correct duration is 3 hours, 1 minute
Can anyone help me with this please ????
Hello @Brooke Anglin
Possible duplicate
You can add some logging and then see the unit of time returned and then you can convert it to the unit you want and return it as "double"
Have a look at the raw number that your subtraction gives you - your scripted field is converting it to text based on the wrong unit of measure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the raw number also doesn't make any sense either. Another example is the duration is 20 min but the number template displays 1,200,000 and the duration template displays 1 week, 6 days, 21 hours, 20 minutes
How can the unit measure be corrected?
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.
WHY DID I NOT THINK OF THAT ?????? I was able to divide by 1000 and it gave me the correct duration
THANK YOU THANK YOU THANK YOU
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you post the final version of the code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Welcome to the Atlassian Community!
All you need to do is convert the milliseconds result on the last "return" lline into seconds (dive by 1,000) or minutes (divide by 60,000)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.