Copy field value from Portfolio Parent Link to Epic down to Standard issues and Sub-tasks

Jeff JEAN October 15, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_

That script is useful, thanks 

However, I've tried to build on and add a level above the Epic based on Advanced Roadmaps "Parent Link" 

The hierarchy is : Feature > Epic > Standard issue > Sub-task 

The Epic is setup/ updated correctly but not the standard issue and the Sub-task levels 

Can you please explain how to include 1 or more levels above the Epic based on Advanced Roadmaps "Parent Link" ? 

2 answers

0 votes
Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2023

The Parent Link field that is provided by Advanced Roadmaps is not the same as the Parent > Child relationship that is inherent between Jira Stories and Sub-Tasks. It is easy to confuse this, so maybe your original script is not accessing the Parent Link field. 

Do your Standard Issues and Subtasks have the actual field present on their screens? 

Is this a Listener? What event does your script execute on? 

Jeff JEAN October 24, 2023

Hi Judah, 

Thanks for your feedback

I'm aware of it :) That is why I couldn't find a way to build that script correctly ! 

I'm only using the "Parent Link" from Advanced Roadmaps to link Epics to their Parent Features. As for the rest, I'm using the standard Parent/Child relationship natively provided by Jira 

I would like to use it as a Listener in the 1st place. This should be fired on the create and update events 

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2023

Do you have the plugin Jira Misc. Workflow Extensions (JMWE) by any chance? If so, you could accomplish what you're after without code.

I am on Jira Data Center which is similar but not exactly the same as Jira Server. That said, you'll probably need a unique listener for each event, issue created & issue updated. 

I'd start by verifying that your standard issues and sub-tasks have been added to your ARM Hierarchy configuration. 

hierarchyExample.png



Below is a script that check's both the parent link field and the linked issue's field to copy a field value from the existing parent issue to a newly created child Issue, when a new issue is created. Make sure that you associate a parent issue by filling in the parent link field on the Create Issue Screen. I believe it should also work for the story > sub-task relationship too. Replace <YOURFIELD> with your field. 





 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.bc.issue.*
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IssueIndexingService
//represents the created issue
def issue = event.issue
//log the issue type
log.warn ("IssueType = " + issue.getIssueType().getName())
//Provides static methods for accessing JIRA's managed components. You need these to do anything to an issue.
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()
//generic object to hold potential changes to an issue
def changeHolder = new DefaultIssueChangeHolder()
//access <YOURFIELD> field object
def <YOURFIELD> = customFieldManager.getCustomFieldObjects(event.issue).find { it.name == "<YOURFIELD>" }
//access the Parent Link field object
def parentLinkField = customFieldManager.getCustomFieldObjectsByName('Parent Link')[0] 
//the value of <YOURFIELD> on the linked issue
def linkedIssueValue = issue.getCustomFieldValue(<YOURFIELD>)
//the value of the parent link field 
def parentLinkFieldValue = issue.getCustomFieldValue(parentLinkField)
log.warn ("parent link field value = " + parentLinkFieldValue)
if (parentLinkFieldValue == null){
    log.warn ("no parent link associated with issue. Parent Link = " + parentLinkField )
    return;
}
//the issue key of Parent Link field, ie the parent issue
def parentLinkFieldValueKey = issue.getCustomFieldValue(parentLinkField).getKey()
log.warn ("parent link field value = " + parentLinkFieldValue)
//stringify the parent issue's issue key
def parentKey = (String) parentLinkFieldValueKey
//the parent issue as an object
def parentIssue = issueManager.getIssueObject(parentKey) 
//the value of <YOURFIELD> on the Parent Issue
def parentFieldsValue = parentIssue.getCustomFieldValue(<YOURFIELD>)
if (parentFieldsValue  == null && linkedIssueValue) {
<YOURFIELD>.updateValue(null, parentIssue, new ModifiedValue(parentIssue.getCustomFieldValue(<YOURFIELD>), linkedIssueValue), changeHolder)
    log.warn ("<YOURFIELD> field copied from " + parentKey + " to " + event.issue)
    issueIndexManager.reIndex(event.issue)
else {
<YOURFIELD>.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(<YOURFIELD>), parentFieldsValue  changeHolder)
    log.warn ("<YOURFIELD> field copied from " + parentKey + " to " + event.issue)
    issueIndexManager.reIndex(event.issue)
0 votes
Jeff JEAN October 23, 2023

Any ideas on how to achieve that using Scriptrunner ? 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events