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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The listener should work. Have you test it? You still need to make appropriate modifications.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Max Lim _Adaptavist_ , no the listener is not working. The date field is not inheriting at all. :(
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.