I need to set up a scripted date field that picks a date from the Due date field.
The scripted date field must pick the most furthest date from that field.
Can someone please help with a script or a similar script that matches this scenario. Thank you
Hi,
What do you mean by "The scripted date field must pick the most furthest date from that field." ?
@Antoine Berry Thank you for the reply.
So, We want to have a scripted date field in "PROGRAM EPIC" issue type
This scripted field must display the farthest date value from the DUE DATE field available in EPIC (related to the Program Epic)
Example:
EPIC 1 (due date) - 4/9/19
EPIC 2 (due date) - 3/9/19
EPIC 2 (due date) - 1/9/19
PROGRAM EPIC (scripted date field) - 4/9/19
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am sorry my brain might be a bit slow on monday morning. Could you provide a screenshot ?
I guess you have a custom issue type (program epic), and you are linking epics to it ? And you want to retrieve the farthest date from all these linked epics ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Lol :) Unfortunately we have the screentshot options disabled for security reasons.
But your understanding is absolutely correct !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Sorry for troubling you. But, can I please some some help on this. I tried using the script mentioned in the below comment, but did not work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
I have had a hard time solving this, as I did not have much experience with scripted fields, but I am glad I succeeded !
Here is the script I used :
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}
def farthestDate
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()
if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
return farthestDate
It checks against the due dates of all linked issues of type "Epic" (make sure this is the exact issue type name).
Screenshot of the configuration :
Result :
Let me know if that works for you !
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Thank you soo much for taking your time on this ! :)
So, this script picks the fathest due date out of all the epics and displays at the Program Epic (higher hierarchy than epic) level ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you need to configure the field to be displayed on Program Epic issue type only :
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Omg ! It worked !! Thank you so much . . you are a genius ! ! :) I ll trt testing it out a couple more times and see if I face any backend issues ! Wow yer the best !!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ahah, I'm glad it worked out. :)
If you have any problem feel free to come back to me !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Just a small request, Is it possible include in the script the below scenario,
If any of the Epic due dates are empty, then the Program epic due date must be empty too.
Thank you :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
Sorry, I was out of office. I modified the script above so that if any linked Epic has no due date, the program epic du date will be empty :
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}
def farthestDate
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
return farthestDate
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Thank you ! Will test this out and let you know :) . . So grateful for your help all the time :):) Thanks again
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hi Antoine, I m so thankful for your solution to this question. Its been going absolutely perfect. But unfortunately, the script fails if any of the EPIC is empty and in a cancelled status. Can you please help with modifying the script so that it skips EPICS which are in CANCELLED status ?
Thank you !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
Glad it has been working so far. I do not see why the script would fail because of a status since it is not tested. Could you please link screenshots to illustrate the issue, especially what "cancelled" means please?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hi Antoine, Due to security reasons, we have Screenshots disabled. So sorry
'Cancelled' is a status we move an issue if we don't want to pursue further. More like, if something gets dropped or if an issue is a replication or was created by mistake, we move that issue to Cancelled status.
So the issue here is, sometimes when an Epic Due Date is empty AND is in cancelled status, it interferes with how the scripted Program Epic Due Date behaves(Since the criteria for this scripted field is to show the farther Epic Due Date, and if any Epic Due Date is empty, this scripted field must be empty too. So, I want the script to neglect an epic if its Epic due date is empty & in Cancelled status
Hope my explanation makes sense.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I have understood, please try this script instead :
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}
def farthestDate
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
def status = issueLink.getDestinationObject().getStatus().getName()
if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate) && status != "Cancelled"){
farthestDate = dueDate
}
}
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()
def status = issueLink.getSourceObject().getStatus().getName()
if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate) && status != "Cancelled"){
farthestDate = dueDate
}
}
return farthestDate
Replace "Cancelled" by the exact status name of your jira instance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry You are the best ! Thank you. Will it be possible to skip on CANCELLED Epic altogether irrespective of their Epic Due Date value ? Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well this script skips epics in "Cancelled" status, is it not what you are aiming for ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Yes, that should do :) Thank you so much ! Also, if an issue is brought back to WORKING status from a CANCELLED status, the script wont fail and catch that right ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The calculated field is calculated each time you load the issue. So no, the script will not fail and catch the date from a "Working" epic. :)
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.
Hi @Antoine Berry , I tested the script, but its ignoring the Epics which does not have a Due Date irrespective of what status the issue is in and displays the farthest date of the remaining epics. :(
I want the Program Epic Due Date to ignore the epics (with Due Dates/empty) which are moved to the Cancelled status.
Apart from that, the Program Epic Due Date must display the farthest date of the Epic Due Dates, & if any any Epic Due Date is empty, it must be empty too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
I am sorry it is hard to catch-up each time and I am a bit confused. Could you please share an example of the current behaviour (and what is wrong about it) and an example of the targeted behaviour ?
Be as precise as possible because I am sick atm and cannot focus for too long (don't worry it's not the corona virus :D).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Get well soon !! I really hope not :) I have had my dose of paranoia about the virus and stocked up on masks, but never wore them :D
I feel terrible bothering you while your sick !
FIRST REQUIREMENT -
PROGRAM EPIC DUE DATE must display the FARTHEST date out of the Epic DUE DATE values, but if any of the Epic DUE DATE is null, the scripted field must be null too. This is currently working absolutely fine ! (Thanks to you)
NEW REQUIREMENT -
Exactly the same as above. But only exception is, this time the script must skip Epic issue types that are in CANCELLED status, irrespective of if they have a DUE DATE value or not. Basically it must ignore all Epic DUE DATE that are cancelled (filled/not filled).
Please take care :):)
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.
@Aisha M Yes don't worry, I'm getting better already. :) I'm sorry I have been busy these last two days, I'll try to have a look by tomorrow. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aisha M ,
This is more clear now, please try this script :
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}
def farthestDate
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
def status = issueLink.getDestinationObject().getStatus().getName()
if (status != "Cancelled"){
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
}
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()
def status = issueLink.getSourceObject().getStatus().getName()
if (status != "Cancelled"){
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
}
return farthestDate
This is working for "Cancelled" status (make sure this is the correct name with the capital C in Jira).
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Good to know :)
The script is working perfect ! Thank you so much !!! you are a genius with the Scriptrunner :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad I could help ! I am really not, I just try to make it work based on all the knowledge collected here. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry You are too humble :) You have helped me sooo much with JIRA, I owe it all to you :):)
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.
@Antoine Berry Hi Antonie. Hope you are well :)
Can you please help me with the below question. I want to know if there is a possibility to use Scriptrunner for updating the Issue Type Link Scheme while creating projects :)
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
I am sorry I have been busy lately. It has been a long time since I used Jira CLI, so I am not sure I could help there. But I see that your issue is being handled by the support, is it getting fixed ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry It okay :)
I don't think so, its impossible to view the ticket , the link is always broken. Also, I looked in to see if I can achieve this using scriptrunner. But, it turns out the LINK SCHEME is an extention of a plugin - Extended schemes for JIRA. So, one person told me that we can't work with Scriptrunner to work on a 3rd party plugin . . :(
Incase you are interested, link to he same question with the Scriptrunner help - https://community.atlassian.com/t5/Jira-Software-questions/How-to-use-Scriptrunner-to-update-the-Issue-Type-scheme/qaq-p/1357002#M74194
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , Hope you are well. :) Can you please help with one more modification to your above script please.
I want the script to work only to CHILD OF CUSTOM LINKS. Can you please help.
With Thank,
Najma
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.
Hi @Aisha M ,
I am sorry I am very busy at the moment. Also with the lockdown I do not have access to my development workstation.
Could you please elaborate about "child of custom links" please ?
I'll try to check in the next two weeks.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Thank you for so much for responding back :) Hope you are well/
I'm using your below script to capture the dates of the Epic Due Date and post the farthest date at the Program Epic Due Date field (scripted field). If any of the Due Date in the Epic is empty, then the scripted field at the Program Epic returns empty.
The script is working great, but considers ALL of the epics associated with the Program Epic. Can you please help me modify the script so that ONLY the child of the Program Epic is considered and no other links
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}
def farthestDate
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
return farthestDate
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
I hope you are well. I am terribly sorry I have not answered before. I only just got access back to my development workstation now. Do you still need help on this ?
If yes, could you please specify exactly what do you mean by "child of program epic" please ? Is that a custom issue link (maybe a screenshot would help) ?
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , Hope you are doing very well & in good health :) And please don't be sorry, I know the situation we are right now is crazy !!
Actually, I somehow got some help and modified the script. After some thousands of trial its finally working with my modification :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I am doing very well for now :) And I am glad you sorted this out.
Feel free to ask if you need help !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry But thank you sooo much for all help you have done in the past :) I literally felt lost with ScriptRunners without you . . lol
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have been happy to help and will continue to be ! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry :) I'm back already to seek your help . . sorry :( Can you please help me regarding the feasibility of the below requirement.
When an Epic's Due Date is populated, but the Baseline Due Date is blank, automatically populate the Baseline Due Date with the Due Date.
Other details:
Let me know if I can open a new post for this :)
Thank you Antoine !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
Please clear or explain these points, I am not sure I understood fully.
Example : User fills the Epic Due Date, so the Baseline Due Date is automatically filled with the same value. User udates Epic Due Date, the Baseline Due Date does not change ?
If the user transitions back to "Ready to planning" , the Baseline Due Date value is cleared eventhough there is an Epic Due Date ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ,
I realized you had helped me with an exact similar requirement before, please check the below link
But, just one more question regarding the previous script you helped me with (the one wayyy above).
So, you helped me with a scripted Program Epic Due Date field that captures the farthest value out of the Epic Due Date values, and if any of the Epic Due Date is empty. It returns null too.
So I have a question, my team wants to have the regular JIRA Due Date field at the Program Epic issue type and this field must show whatever value the scripted Program Epic Due Date is showing. Will it be possible ?
Thank you !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
By "JIRA Due Date", Do you mean the due date of issues others than Epic ?
As long as there is a link between issues, it is possible to copy values. But then ask yourself why do you need to copy, and why not use the source field. You do not want to get a "Field-ception".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry So, basically, the below is the exact explanation,
So, we have a scripted Program Epic Due Date - This field displays the farthest Due Date (JIRA FIELD) value from the Child Epic of the Program Epic Issue type.
Example -
PROGRAM EPIC 1
Program Epic Due Date - 1st Dec
CHILD EPIC 1
Due Date - 1st Dec
CHILD EPIC 2
Due Date - 10th Aug
Since the above is the existing process, we have removed the Due Date (JIRA field) from the Program Epic issue type screens. Now, they want to have the Due Date field at the Program Epic issue type, and this Due Date must simply display whatever the Program Epic Due Date (Scripted field) is displaying without being editable. Is it possible, or should I add a new scripted field to simply copy and display the value ?
Hope I made sense..lol, I'm sorry :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes that makes sense. Unfortunately you cannot add a new scripted field because, well, it creates a new field. So you would need a listener on the child epics to calculate the program due date each time one of the child due date is changed.
That is if you need the field value in real time. Otherwise you could have a service running at regular intervals calculating the due date for each program epic.
On which screens can the users update the due date of the child epic ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry Will it be possible to create a Custom listener for the "Issue created" and "Issue Updated' events, for the Program Epic Issue Type alone ,that simply copies the value of the "Program Epic Due Date' value and display it at the regular Due Date (This Due Date I ll add it only to the View screen of the Program Epic issue type.
Also, the users update the Due Date while creating an Epic (So, the Due Date field is added to the Epic issue type screen)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you wish to keep the Program Epic Due Date ?
Because what you are proposing (if I got it right) is :
Step 1. User updates due date on Child epic 1.
Step 2. Program Epic Due Date (scripted field) is calculated on Program Epic.
Step 3. Customer listener copies Program Epic Due Date on Due Date field.
Assuming that it works (i.e. step 3 always occurs after step 2 which I am not even sure), would you agree that step 2 is unnecessary ? We might as well directly copy the Due Date from the Child Epic to the Program Epic, right ?
That is why I am asking the screens used to change the Due Date on child epics, so that we can identify which events are triggered.
As a side note I think the scripted field is the most appriopriate way to achieve your requirement (calculated automatically, keeps the listeners clear and avoid to call a script when it is not needed) so I would really question the need of having the due date used instead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry The reason we need Step 2 , is the scripted field only displays the farthest date out of ALL THE CHILD epics associated with that Program Epic Issue (thro issue links) and if any one of the Epic Due Date is empty, this scripted field returns an empty value too. So, they really need it.
But, for tracking & audit purposes they want a Due Date field displaying the value whatever the scripted field is displaying.
The Program Epic Due Date (scripted field) is updated when a Child Epic is created with the Due date, or even maybe when a Child Epic is later updated with the Due Date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry My manager was able to achieve this using JIRA Project Automation. lol . But, he has asked me to check if the listeners could work too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well I am still not clear why you need the Program Epic due Date (scripted field) if the due date needs to be the exact copy.
But if you need both the due date and the Program Epic due Date (scripted field), I would argue that scriptrunner might not be the best app to copy the value. It can be done (I think) but will add unecessary processing and harder maintenance.
If you achieved this with another app such as Project Automation, where all you have to do is configure the automatic replication I would use this.
The Program Epic due Date (scripted field) calculation is pretty cool with scriptrunner though I think and is probably the most suited app for that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Yayyy, the comments are back !! :D
Yes, true. But, there is a check box under the automation quoting that, the instance might get slow. So, they want to try out the listener option too.
Will it be possible to copy the these values for the Program Epic Issue type alone using the listeners ? Can you please help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is my first take :
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.index.IssueIndexingService
import java.sql.Timestamp
if (issue.issue.getIssueType().getName() == "Epic"){
def programEpic
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Program Epic"}
if (issueLinks.isEmpty()){
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Program Epic"}
if (!issueLinks.isEmpty()){
programEpic = issueLinks[0].getSourceObject()
}
}
else {
programEpic = issueLinks[0].getDestinationObject()
}
if (programEpic){
allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(programEpic.getId()))
issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}
def farthestDate
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (dueDate == null){
programEpic.setDueDate(null)
programEpic.store()
issueIndexingService.reIndex(programEpic)
return
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(programEpic.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()
if (dueDate == null){
programEpic.setDueDate(null)
programEpic.store()
issueIndexingService.reIndex(programEpic)
return
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
programEpic.setDueDate(farthestDate)
programEpic.store()
issueIndexingService.reIndex(programEpic)
}
}
Create a script listener on issue created/updated (or any event triggered by a due date change). This is assuming that your issue type name is "Epic" (first if condition).
The script then checks if there is a program epic linked. Then it goes through the same logic as above.
The problem is that the due date will be calculated each time the listener is triggered (for any other update as well)... We might want to improve that by creating two listeners, but let's see if this works first.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Wow, I din realize the script would soo bigg. Will check now.
The copying values should be available at the Program Epic Issue Type
The Program Epic Due Date (available at the Program Epic Issue Type)
Due Date (copies what the above field is displaying, at the Program Epic Issue Type)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , I tested out the script. I added the listener for "Issue created' & "Issue Updated".
All the below scenario is displayed at the Program Epic Issue Type
The Due Date is displaying the Program Epic Due Date's value only the first time. Later, it does not change the value.
When the Program Epic Due Date is empty, the Due Date is still showing the first value.
Then, when the Program Epic Due Date is showing a new value, the Due Date is still showing the first ever value & doesn't update with the changing values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
By the way this script is not interacting with the Program Epic Due Date, it is just calculating on its own, following the same pattern.
So, it it works on the first time it is a good sign I guess. Now we need to debug why it is not working afterwards.
1st. Can you confirm that the issue types are exactly "Epic" and "Program Epic" (as I test against those values in the script) ?
2nd. On the script listener page, can you make sure the script listener is running when it is supposed to ? Is it failing ?
3rd. If it does not fail, you should add logs in the script to check what is executing (I can help if needed)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ,
Yes, the issue names are correct.
Oh, so the listener, is re-doing the entire function taking place on the scripted field (Program Epic Due Date) and displaying the result at the regular Due Date field ?
I'm getting the below error on the listener page,
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2020-07-17 04:40:33,340 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2020-07-17 04:40:33,341 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null groovy.lang.MissingPropertyException: No such property: issue for class: com.atlassian.jira.issue.IssueImpl at Script21.run(Script21.groovy:6)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, typo on my part... just remove one issue.
if (issue.getIssueType().getName() == "Epic"){
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , Its not working unfortunately :( Anyway, below are the steps I followed.
But, the Due Date is not showing the value the Program Epic Due Date (scripted field) is showing when it changes.
Example,
When I alter the Due Date in the Epic issue type to a more farther date, the Program Epic Due Date (scripted field) at the Program Epic issue type shows the new value, but the view only field Due Date at the Program Epic still shows the old value.
Also, below is the listener script we have for calculating the Program Epic Due Date. We had modified,
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def farthestDate
def issueLinks
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
issueLinks = allOutIssueLink?.findAll() { (it.getDestinationObject().getIssueType().getName() == "Epic") && (it.getIssueLinkType().getOutward() == "Parent") }
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
return farthestDate
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
Yes I had provided a generic script, it is nice that you simplified it according to your context. I have simplified my listener script according to it and added some logs :
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.index.IssueIndexingService
import java.sql.Timestamp
log.error("working on issue : " + issue)
if (issue.getIssueType().getName() == "Epic"){
log.error("the issue is an Epic")
def programEpic
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Program Epic"}
if (issueLinks.isEmpty()){
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Program Epic"}
if (!issueLinks.isEmpty()){
programEpic = issueLinks[0].getSourceObject()
}
}
else {
programEpic = issueLinks[0].getDestinationObject()
}
if (programEpic){
log.error("found the program epic : " + programEpic)
allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(programEpic.getId()))
issueLinks = allOutIssueLink?.findAll() { (it.getDestinationObject().getIssueType().getName() == "Epic") && (it.getIssueLinkType().getOutward() == "Parent") }
def farthestDate
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (dueDate == null){
programEpic.setDueDate(null)
programEpic.store()
issueIndexingService.reIndex(programEpic)
log.error("the due date is null ! ")
return
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
programEpic.setDueDate(farthestDate)
programEpic.store()
issueIndexingService.reIndex(programEpic)
log.error("updating due date with value : " + farthestDate)
}
}
Please update your listener with this script. Add a due date on an Epic, check if the listener executed successfully with the method above, and provide the printed logs. That should help a lot fixing the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello @Antoine Berry , Good news & bad news :D Well, the script is working if the Program Epic Due Date has a value. But, if the Program Epic Due Date (scripted field) is empty (Because if a Child Epic is empty), then the Due Date does not become empty, it shows the last value the scripted field was showing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
could you check the logs on the listener page please (G+G > Script listeners)
Check the date is correct and what went ok / wrong (you can paste the screenshot here).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry I was wrong I guess, its not working at all :( Due Date is not showing the value of the Program Epic Due Date, even if it shows an update value or null, the Due Date is still showing some older value.
I checked the log & there were no recent updates. It was still showing the date as yesterday.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay but I need to see the logs to be able to help :D
If the scripted field does work, I see no reason why the listener would not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hi. We have the snipping tool & Print screen disabled :D Sometimes, I wonder if copy pasting the error could get me in trouble too :P
The below log report is green . . with the following text
Time (on server): Tue Jul 21 2020 14:00:50 GMT+0530 (India Standard Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2020-07-21 03:30:50,946 ERROR [runner.AbstractScriptRunner]: working on issue : ADOM-45
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, makes sense then. the update will work when you update the due date on an Epic.
Please do so and immediately check the script listener execution.
It should start with
working on issue : ATLASDOM-XXX
ATLASDOM-XXX being the Epic you just modified.
Then copy the rest of the log :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry But ADOM is the Program Epic. Also, when I update the Epic Due Date, the scripted field captures the change, but the listener enabled Due Date (at Program Epic) does not change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need to make sure the listener is triggered when you update the due date of the Epic. Both Epic and Program Epic are in the same project right (ATLASDOM) ?
That is why I am asking for the logs, I cannot help if I do not know what is going on. I used the same script logic as the Scripted Field.
It is the Epic that triggers the update, not the Program Epic. So make sure the listener is triggered on the Epic Issue updated/Issue created.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Oh okay . . . Actually both the Epic and Program Epic are related through the Child - Parent issue link.
Okay, I think, i got it. I had enabled the listener only for the Program Epic project & not the associated Epic project. Maybe that's the problem, its failing :O
Also, our DEV has crashed :D:D I ll test it soon, maybe I'll check & update tomorrow :)
Also, thank you so much, I really really owe you so much for all the help :) Nobody takes the effort to help this much ;( Thank you !!!!!!!!!! ^_^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hi ! The script is working perfect after I added both the Program Epic & Epic related projects to the listener and now its working :):) yayyy, Thank you !!!!!!!!!!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M glad we could make it work eventually :)
Now you might want to disable the scripted field to avoid unecessary processing.
Would you mind creating a new question for this last part (just copy your requirements from above), so I could post a clean answer (better clarity for others) and get an accepted answer (would really appreciate it since it has been busy lately on my side). Same for the other question with discussed would be perfect. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Most definitely !!!!
Can you please paste the answer to the below link,
Also, will there be any problem if the scripted field exists ?
Thank you so much !!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You might want to change the tag cloud to server (and maybe add groovyrunner) on the question. :) Thanks for creating it !
The scripted field is not a problem, but now you have a duplicate with the due date, and the scripted field is calculated each time the issue is loaded. So you might want to comment the code in the scripted field to avoid some processing. If you want to get it back, you can simply uncomment it.
Again you are welcome happy to help !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hello. I'm sorry, I couldn't understand :( What needs to be commented in the Scripted field ?
Will the users face any sort of confusion if the listener & the scripted field exists ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M ,
You simply need to edit your scripted field :
And add "/**" before the first line and "**/" after the last line. It will comment everything in between (which means the code will not be processed) :
If you want back the value of the scripted field, just remove the "/**" and "**/" tags.
As for the user, it depends on which fields they are using. But as an admin you should try to remove the duplicates, especially when this one involves a processing each time an issue is loaded.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry All the comments seems to have gone :o
I read your comment through an email notification though :) But, he insists to have the listener solution as well. Is it possible to simply copy the values and create a listener for "Issue created, and issue updated" events?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Community Manager! Sorry to disturb, but all the comments have disappeared from this question and this one as well. The history is empty... Maybe we have flooded too much ?
Thanks for helping, and sorry if you are not the one I needed to tag.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry The comments are gone for every post. Even the ones with very limited comments. FYI :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh ok... I checked a few posts but the comments were still there... So it might be a global issue but still linked to specific posts ? Then I probably pinged Erica for nothing, I hope they will come back >_<
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry I hope they fix it. You had helped me with a lot of solutions to script related questions, should be helpful for someone !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Hey, Antoine! I'm seeing a ton of comments on both of those posts, so perhaps it was temporary? Let me know.
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.
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dueDateField = customFieldManager.getCustomFieldObjectByName("Due Date")
List<IssueLink> linkedIssues = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId())
if(linkedIssues.size() < 1){
return
}
def farthestDate = new Timestamp(Long.MIN_VALUE)
for(IssueLink iLink : linkedIssues){
def iLinkIssue = issueManager.getIssueObject(iLink.getId())
log.error(iLinkIssue.getId())
Timestamp dueDate = (Timestamp) iLinkIssue.getCustomFieldValue(dueDateField)
log.error(dueDate)
if(dueDate.after(farthestDate)){
farthestDate = dueDate
}
}
return farthestDate
You will need to configure your Farthest Date to be a Date Time range picker in the custom field settings page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much for the comment !
So, will the script display the farthest day of the Epics linked at the Program Epic (issue type higher than epic) level ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem! Yes it will get the inward links of the Program Epic (as long as you put it on the screen for that issue type) which will be various Epics. From there it'll loop over the linked issues (there is no checking that they're of a specific issue type, you can add this in if there will be other issue types linked to this issue) and find the farthest date out of all their due dates.
Let me know if there are any problems!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tom _Automation Consultants_ Thank you so so much for helping out ! :)
I did follow all of the steps. But my Program Epic is not showing the farthest date from the due date values in epic. dunno where I m going wrong
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aisha M If you go to the Scripted Fields part of ScriptRunner in the Add-ons settings there will be outputs to the logs, could you attach a picture of the most recent log?
Also on the Program Epic issue can you in the Admin section select the Where is my field? button and search for the scripted fields name and attach that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tom _Automation Consultants_ Well, do to compliance issues, we do not have sceenshots emabled. But, I copied the log output,
2019-04-08 07:20:34,878 ERROR [customfield.GroovyCustomField]: ************************************************************************************* Script field failed on issue: ATLAS-570, field: Farthest Date java.lang.NullPointerException: Cannot invoke method getId() on null object at Script6.run(Script6.groovy:21)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if(iLink == null){
continue;
}
can you add this bit of code just beneath the for(IssueLink iLink : linkedIssues){ part of the code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tom _Automation Consultants_ The script seems okay with no errors (at the inline script screen). But I m still not able to see the farthest date field value on the PROGRAM EPIC issue. I have added the scripted field to the relevant screens & everything . . But still doesn't show up. Don't know where I'm going wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.