Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Flow down selected date to another issue type based on links.

My team has their hierarchy built in the following manner:

 Epic -> Feature -> Story

This is achieved by linking issues with the derivation issue type between features and stories. On our Feature, we have a date picker custom field in which a due date can be selected. We have scriptrunner and I am trying to achieve being able to autopopulate the STORY'S due date with the same date that has been entered for the FEATURE. 

 

Would someone be able to help me out with a script for this? I've done this before with multi-select lists, but I can't get the script to work for the date picker. Thanks so much!

1 answer

I assumes you want to set Story's due date after Story issue creation via a post-function and the link to feature is selected in creation.

As an example, I am creating an issue with a link "causes" to another Isuue. The issue link type name is "Problem/Incident". After creation, newly created issue should have the same date picker field value as the linked issue.

1. Navigate Project Settings > Workflow > edit your workflow > add post-function on "Create" transition > add post-function > choose "Custom script post-function".

2. Use following script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def problemIncidentIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id).find {it.issueLinkType.name == "Problem/Incident"}
def linkedIssue = problemIncidentIssueLink.getDestinationObject()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Just Date Picker").first()
def linkedIssueDate = linkedIssue.getCustomFieldValue(customField)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issue.setCustomFieldValue(customField, linkedIssueDate)
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)

3. Remember to move the order of this post-function to be after "Creates the issue originally".

Depends on your link setup, you might want to use getInwardLinks() instead of getOutwardLinks(), use getSourceObject() instead of getDestinationObject().

A lot of our stories and features are written in advance without due dates assigned at the time of composure. Once the features have been reviewed, they are assigned a due date. We update that field in the feature, so ideally when we update the feature, the stories would automatically update as well.

Can you confirm that the Due Date is a custom field, not the system field?

This should be done via a listener on Issue Created event and Issue Updated event.

The script logic is a little different because you want to only set the Due Date custom field when the Feature issue update.:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as MutableIssue
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Just Date Picker").first()
def problemIncidentIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id).find {it.issueLinkType.name == "Problem/Incident"}
def linkedIssue = problemIncidentIssueLink?.getDestinationObject()
def linkedIssueDate = linkedIssue?.getCustomFieldValue(customField)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (issue.issueType.name == "Feature" && linkedIssueDate) {
issue.setCustomFieldValue(customField, linkedIssueDate)
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)
}

This is not the most efficient script. but the script is simple enough to not warrant any meaningful improvement.

If you really want to improve efficiency, you only update the issue when the Due Date custom field value changes. To check that, you can use ChangeHistoryManager.getChangeHistories() method and ChangeHistory class. As an example:

import com.atlassian.jira.component.ComponentAccessordef 

changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

log.warn changeHistoryManager.getChangeHistories(event.issue).last().getChangeItemBeans() 

 

Like Vikrant Yadav likes this

Correct, it is a custom field. It's not titled "Due Date" exactly. I'd like to only update the issue when that field changes. Thanks!

The listener should work. Have you test it? You still need to make appropriate modifications.

Hi @Max Lim _Adaptavist_ , no the listener is not working. The date field is not inheriting at all. :(

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

694 views 2 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you