Script to Update Custom field with last date.

siva October 6, 2019

I Have a EPIC and three stories in it.

 

Need to use a post-function or listner Script to update the Date field ( DUE DATE) of the EPIC.

 

1. The script needs to check DUE DATE field of the three stories.

2. The farthest date in the ( DUE DATE ) should be updated DUE DATE field of EPIC.

 

Any suggestions for the same. 

1 answer

1 accepted

2 votes
Answer accepted
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 6, 2019

Hi siva,

What about to place an Scripted field instead at the Epic level?

 

You must tune this code to fit your needs

 

/*
* @Author: Jack Nolddor [Sweet Bananas] <support@sweetbananas.es>
* @Date: 06-Oct-2019
*
* @Description:
* Field that returns the further date from the configured linked issues
* You must to use Date Time Template
* You must to use Date Time Range picker Searcher
*
* See the link below for further details:
* https://community.atlassian.com/t5/Jira-questions/Script-to-Update-Custom-field-with-last-date/qaq-p/1196044
*/

import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.atlassian.jira.issue.link.IssueLinkManager


def log = Logger.getLogger("com.nolddor")
log.setLevel(Level.DEBUG)

@PluginModule
IssueLinkManager issueLinkManager


//--------------------------------------------------------------
// You must change the following variables as your needs
//--------------------------------------------------------------
def sourceIssueTypes = ["Story"]
def excludeResolvedIssues = true
//--------------------------------------------------------------

// Look for all linked issues
def linkedIssues = issueLinkManager.getOutwardLinks(issue.id)*.destinationObject
// Remove undesired issue types
linkedIssues = linkedIssues.findAll{it -> sourceIssueTypes.contains(it.issueType.name)}
// Remove resolved issues, if applicable
if(excludeResolvedIssues)
{
linkedIssues = linkedIssues.findAll{!it.resolutionDate}
}
// Sort remaining linked issues by dueDate
linkedIssues.sort{it.dueDate}
// Return the further dueDate
if(linkedIssues)
{
return linkedIssues.last().dueDate
}

 

 

 

Let us know if the provided code snippet solves your problem,

Regards

siva October 6, 2019

@Jack Nolddor _Sweet Bananas_ 

 

Thanks, this does the job.

 

can you add a script line to check issues with are not closed or completed.

CLOSED issues should not be considered.

Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 6, 2019

I've improved the given script to also remove the resolved issues ;) Enjoy!

 

Did my answer solve your problem?

If so, consider to mark the proposed solution as an 'Accepted answer'. This will help other people with the same or a quite similar problem to find a solution in a easy and faster way.
Otherwise, if you solved the problem in a way that hasn't been suggested yet in this thread, please I encourage you to reply your original message to tell us what was the final solution for the problem, you can also mark your own reply as an 'Accepted answer'.

In addition, by doing this the post will automatically gain the "Solved:" prefix in search results to indicate other people that no further support is needed.

Kind Regards.

siva October 6, 2019

@Jack Nolddor _Sweet Bananas_ 

THANKS, JACK,, that was quick.


I'm off work now, compiled against a ticket shows the right data.

 

WORKS..!!

I might need another script from you, will update the details ( similar to the present one)

few changes would do.

Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 6, 2019

Glad to help, just summon me on the new thread if needed ;)

Happy coding!

siva October 7, 2019

@Jack Nolddor _Sweet Bananas_ 

 

You must to use Date Time Template
* You must to use Date Time Range picker Searcher

i have selected Date Time Template.

 

But When Date Time range picker serarcher im not able to create issues. 

Suggest an answer

Log in or Sign up to answer