Groovy script help: how to set EPIC's Due Date field, by getting "Issues in Epic" issues Max Due Date updated?

Hi,

I need to set the EPIC's Due Date field, by traversing all the "Issues in Epic" of specific Issue Type and get the Maximum(greater one) Due Date set for a Issue to be copied to EPIC's Due Date?

Can some one help me on how to achieve this ! Thanks. 

  • Manju

 

1 answer

1 vote
Tarun Sapra Community Champion Jul 29, 2016

Hi 

It's doable with scrpit runner, for a epic there can be direct subtasks or can be outward links. What you need to do is traverse over all the linked issues or the sub-tasks and just keep storing the largest date as in groovy the comparison operators ( >,<) are supported for date types

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def greatestDate;
issueLinkManager.getOutwardLinks(issue.id).each {issueLink -&gt;
    if (issueLink.issueLinkType.name == "&lt;Name of Link&gt;") { 
        def linkedIssue = issueLink.destinationObject
       
    }
}

 

or in case of subtasks

issue.getSubTaskObjects(){ &lt;code bloc as above&gt;}

 

and in each code block you can have a field "largestDate" which you compare with each date and set the greater date's value in this field. Just like here - http://www.java-examples.com/find-largest-and-smallest-number-array-example

Hi Tarun,

I has written the groovy script to modify the EPIC Due Date value into another Due Date value from the linked Issues Max Due Date set as below:

But I am getting error, while doing this set operation:: epicLink.setDueDate(issue.dueDate);

Cann't find matching method; please suggest why it's so??

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
log.setLevel(org.apache.log4j.Level.DEBUG)
def issue = issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
def epicLink = issue.getCustomFieldValue(epicLinkCf) as Issue
def dueDate = epicLink.dueDate
log.debug (dueDate)
log.debug (issue.dueDate)
if (! issue.dueDate){
throw new InvalidInputException("Release requested 'ITG_IN' Due Date is to be updated, to Commit the code changes into planned Release branch !")

if(issue.dueDate > dueDate){
epicLink.setDueDate(issue.dueDate)
log.debug (issue.dueDate)
log.debug (dueDate)
return true }

Tarun Sapra Community Champion Aug 08, 2016

why are you doing this

def epicLink = issue.getCustomFieldValue(epicLinkCf) as Issue

you are retrieving a customFieldValue as an Issue, why?

I have pasted the code and that should do the trick and help you get the list of all the issues -

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
 
def greatestDate;
issueLinkManager.getOutwardLinks(issue.id).each {issueLink -&gt;
    if (issueLink.issueLinkType.name == "&lt;Name of Link&gt;") {
        def linkedIssue = issueLink.destinationObject
        
    }
}

Sorry Tarun, I missed to explain you the change in my requirement for the above posted groovy script:

Now instead of traversing from EPIC to "Issues in Epic". From the specific "Issues in Epic" issue type, I will try to get the EPIC's Due Date and comparing with "Issues in Epic" issue type's Due Date. 

In case "Issues in Epic" issue type's Due Date is greater than the EPIC Due Date, I need to modify/set this bigger date as EPIC's Due Date for my EPIC.

This is my requirement to add the above groovy script just now posted.

But in this case, I need help on how to set the epicLink.setDueDate(issue.dueDate) in case if(issue.dueDate > dueDate) is True.

Also I need to change/set the EPIC JIRA Issue status along with modifying the EPIC's Due Date, based on the "Issues in Epic" Issue Type's Status after validating the Due Dates as explained above. 

I tried to use issue.setDueDate(dueDate) function to set it but this method doesn't exit to set the EPIC due date !

Please advice on how to set the EPIC's Due Date based on the script posted above.

Tarun Sapra Community Champion Aug 09, 2016

Epic is also a instance object of type MutableIssue which has the setDueDate method, please see here - https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/issue/MutableIssue.html

Are you new to groovy or Java?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
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