Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with listener to copy a scripted field value to a regular field ?

Aisha M
Contributor
July 28, 2020

We have a scripted PE Date - This scripted field displays the farthest Due Date (JIRA FIELD) value from the Child Epic of the Program Epic Issue type. 

Now, we want to have the regular Due Date field at the Program Epic issue type screen, and this Due Date must simply display whatever value the PE Date (Scripted field) is displaying without being editable. 

Also, The scripted field works on the logic that it displays the most farthest date from the Epic DD values and , when an Epic associated with the Program Epic does not have a Due  value, then the scripted field returns a null value.

 

1 answer

1 accepted

2 votes
Answer accepted
Antoine Berry
Community Champion
July 28, 2020

Hi @Aisha M ,

As I understand it you need to set the farthest (i.e. the oldest) of the epics due date on the program epic due date. My advice is to create a script listener on every event that may be triggered when you set the due date on an epic. These events would most probably be Issue created, Issue updated and maybe others if you are updating the due date on a transition (you need to check your workflow post function in that case).

Add this script below. It will check if there is a Program Epic linked to it, and then all its linked epics to retrieve the farthest due date. I have added a few log lines to help debugging if needed.

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)
}
}
Aisha M
Contributor
July 28, 2020

@Antoine Berry  Works perfectly ! Just had to ensure that the projects that has the PE issue & Epic issue must be enabled on the listener page :) Thank you :)

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events