ScriptRunner - scripted field showing parent's due date

Jenny Bellas July 10, 2017

I have a ScriptRunner Scripted field (called Parent Due) on my sub-tasks where I want to show the parent's due date. 

Here is my script:

/* Displays the parent's due date.
Applicable Sub-Tasks and Financial Sub-Tasks. */

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.core.util.DateUtils

// get the current issue's parent
def subTaskManager = ComponentAccessor.getSubTaskManager()
def parent = issue.getParentObject()
def due

// if current issue does not have subtasks, use the issue's remaining estimate and time spent
if (parent != null) {
due = parent.getDueDate()
return new Date(due.getTime())
}
else {
return null
}

 

The server time is Central time zone and I am in Mountain. So parent's date is 30/Jun/17 and I am getting 29/Jun/17 11:00 PM as my result. 

I really want to use the date in a JQL query such as ... "Parent Due" = endOfMonth(-1) so I need a date returned.

1 answer

0 votes
Stephen Cheesley _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.
July 11, 2017

Hi Jenny,

I've tried to reproduce your issue. If I understand what you've said correctly, you are seeing a different due date on screen to what you are seeing that the server has produced? I have tried to reproduce this error with your script and I am unable to. I have even tried to change the timezone on the user profile and I still see the same due date.

Have you tried the JQL search? Are you seeing expected results from that?

Jenny Bellas July 11, 2017

Thanks so much Stephen for trying to reproduce. I'll try to add additional details so that maybe you can reproduce successfully:

Q; If I understand what you've said correctly, you are seeing a different due date on screen to what you are seeing that the server has produced?

A: The parent's Due date stored on the server is Fri Jun 30 00:00:00 CDT 2017 (Central time) and I see 30/Jun/17 in the parent's Due date field. My computer & user profile is set to MT (Mountain time).

For the  Parent Due field, I see 29/Jun/17 11:00 PM on the screen but when I hover over it, a little hover display shows me 30/Jun/17 12:00 PM (see screen print below). This makes me think it is stored correctly but showing incorrectly.

screen1.PNG

fyi ... I have my template and searcher set to be Date Time pickers.

screen2.PNG

Q: Have you tried the JQL search? Are you seeing expected results from that?

A: Yes, I have tried the JQL search. If I add a Due date to the sub-task, then my query Due = endOfMonth(-1) returns the record but if I try Parent Due = endOfMonth(-1) does not return the record.

So really my end goal is really to not have to maintaing a due date on all the sub-task records as it will be the same as the parent's due date. But I need to query all the sub-tasks for a certain month, so I need the date. Any other sugguestions are welcome. Thanks!

Stephen Cheesley _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.
July 12, 2017

Hey Jenny,

Thanks very much for the clarification. I think you might be able to do this in a simpler way, that better suits your needs by using the subTasksOf scriptrunner function.

So I ran the following query:

issueFunction in subTasksOf("Due = endOfMonth(-1)")

This will return you all subtasks of the issues returned by the specified query.

This should give you the desired results without the need for the script field.

Does this work for your scenario?

Jenny Bellas July 12, 2017

Yes! That works for me. Thanks SO much for the support!

Stephen Cheesley _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.
September 5, 2017

Hey Jenny,

I am glad to hear your issue is resolved :-)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events