Behaviours - getting a subtasks parent DueDate

Will C
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.
March 25, 2019

Hi there,

 

I am trying to write a script that wont let you edit, create a subtask if the due date is further in the future than the parent issue.

I have searched on various old posts and thought I could do this by using

Jamie's example here - https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/subtask-default-fields.html

or I have seen you can get the parent by using underlyingissue.parent or getparent()?

In the past in other areas of scriptrunner I can use issue.getParentObject

how can I get the parent due date so I can compare it to the child due date?

Can you also look at the below, I have changed this I am comparing custom fields on the same issue but ignore the script for now, is this in the right place? or should it be on the initialiser if I want to get it for parent duedate?

 

Behaviours.JPG

 

3 answers

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2019

Hi,

If you simply need to compare the issue's due date to the parent's due date you can use this code (remember that you need to check that the issue is created and that the parent exists) : 

def dueDate = getFieldById("duedate").getValue()
if (underlyingIssue?.getParentObject()){
def parentDueDate = underlyingIssue.getParentObject().getDueDate()
}

You can then compare them : 

if (dueDate.compareTo(parentDueDate) > 0){

getFieldById("duedate").setError("The child due date value must be set prior to the parent due date")

}

Antoine

Will C
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.
March 25, 2019

thank you for the help with this, I take it that on edit issue that you can't use parentissueid field? that was the piece I was stuck on.

Like Antoine Berry likes this
0 votes
Andy Hurley April 27, 2023

I have a similar problem in that I want to populate the summary based on the parent summary and I want this to show during the create process to avoid confusion so a post-function is not suitable. The problem I have is that the underlyingIssue is not populated during create so I can't find the parent. Jira must know the parent issue when creating a sub-task but I can't seem to find a method to get at this.

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2019

Hello @Will C 

This is a possible duplicate

https://community.atlassian.com/t5/Jira-questions/Limit-Duedate-of-Subtasks-based-on-their-Parents/qaq-p/678348

As far as configuration in behaviour is concerned, then your script should be mapped to the dueDate field in the sub-task for the field mapping.

Suggest an answer

Log in or Sign up to answer