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.
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 -> if (issueLink.issueLinkType.name == "<Name of Link>") { def linkedIssue = issueLink.destinationObject } }
or in case of subtasks
issue.getSubTaskObjects(){ <code bloc as above>}
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 }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 -> if (issueLink.issueLinkType.name == "<Name of Link>") { def linkedIssue = issueLink.destinationObject } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Thank you Tarun !
Well, I just mentioned 3 epics as an example. The program epic can have any number of epics under it.
Also, for comparing the dates, should I use a similar syntax as you have mentioned above for this original post or something like below,
//Initialize min and max
def minDate = storyDates[0] as Date
def maxDate = storyDates[0] as Date
//Find actual min and max Dates
for(int i = 1; i < storyDates.size(); i++)
{
def currentDate = storyDates[i]
if(currentDate.before(minDate))
{
minDate = currentDate
}
if(currentDate.after(maxDate))
{
maxDate = currentDate
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Hi Tarun,
In your code I have an error at
SearchResults searchResults;
Error - Unable to resolve class Search Results
Any help on how to fix it , please. Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to have the import statement
import com.atlassian.jira.issue.search.SearchResults
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Getting a lot moree errors sfter adding the import statement . . It says "SearchService" is undeclared
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Also, can you please post your script under the below link, so that I could mark yer reply as answer after it works :) Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
You have to declare and import the classes and variables which you are using in your code, I suggest you to do go through a basic java and groovy tutorial else it will be very hard for you to use the SR plugin as it does require some level of programming proficiency.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tarun Sapra thank you much for your help so far with this, and also with other questions. Really appreciate it :)
And yes, I understand this requires some level of scripting knowledge, but unfortunately we don't have anybody as such to help me out here. Also, our work with SR is limited to a minimum. So, just looking for ways to create like a sample script, so that I can work on it bit by bit and somehow make it work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
What do you mean by "farthest due date"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Hello:)
My scenario is, I want to have a scripted field in PROGRAM EPIC. So what this field should basically do is, it must automatically pick the most late date based off the "DUE DATE" field in the EPIC.
Example: If
ABC EPIC-1 DUE DATE is 08/10/18
ABC EPIC-2 DUE DATE is 10/10/18
ABC EPIC-3 DUE DATE is 12/10/18
ABC PROGRAM EPIC scripted DATE field should automatically pick 12/10/18
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How is the Program Epic connected to the 3 epics? Is it connected via normal issue linking feature of Jira or via child issues of portfolio?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
Since it's connected via child issues, then it means the 3 epics are connected to "Program Epic" via parent link? Am I correct. As Parent link is the default portfolio field at epic level which makes it visible to which Program epic/initiative an epic is connected to.
Now, in order to show the farthest date you on Program Epic you first have to fetch the 3 epics and then compare their date.
This is how to fetch the 3 epics (as all 3 should have parent link field on the view screen pointing to the program epic) So the scripted field is present on the program epic has the code
def issueKey = issue.key;
//issue is the implicit object available
def jqlSearch = "'Parent Link' =$issueKey"
getListOfEpics(jqlSearch).each {
def date = it.getDueDate()
//write code to compare dates.
}
//issueKey is key of program epic
List<Issue> getListOfEpics(String jqlSearch) {
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser;
def issues = []
def searchService = ComponentAccessor.getComponent(SearchService)
SearchResults searchResults;
def parseQuery = searchService.parseQuery(user, jqlSearch);
if (parseQuery.isValid()) {
searchResults = searchService.search(user, parseQuery.query, PagerFilter.getUnlimitedFilter())
if (searchResults && searchResults.issues) {
return searchResults.issues;
}
}
return issues;
}
Now, you just need to write the code to compare dates and that should be it.
In the method getListOfEpics - We execute JQL query to fetch all epics which have the same parent link i.e. same program epic upon which this scripted field is present.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tarun, Can I use the syntax you had mentioned above for my scenario ?
I want a scripted field on Program Epic, which picks the farthest due date value of the epics.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.