ScriptRunner - scripted field showing parent's due date Edited

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

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?

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!

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?

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

Hey Jenny,

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

344 views 0 1
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you