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

Inherit Components from Epic to User Story, Epic link updated

Gsep Support Dec 07, 2017

Hi,

Could somebody correct me with below script:

Create a user story, "Component" field should be empty. 
Update Epic Link for user story, Component field should be copied from Epic to User Story. I am user Script listener with "issue updated" Event.

I have below script, could any one correct this script:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.util.ImportUtils

MutableIssue issue = (MutableIssue) event.issue;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()

// Check if Issue Type is Story
if (issue.getIssueType().getName() == "Story" ) {

// Get Custom Field as string (Epic Link)
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")

// Get Custom Field Value as String
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
String EpicName = issue.getCustomFieldValue(epicLink);

if(EpicName){
// Get Epic from Issue
def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue

// Get Component from Epic
def currentValue = epicIssue.getComponents()

// Set component to Story
issue.setComponent(currentValue)
}
}

1 answer

0 votes
Marc Minten (EVS) Dec 07, 2017

Hi,

I did some similar things, but I never used the custom field Epic Link as it is not clear what kind of data type is in it. I guess that your "...getCustomFieldValue(...) as Issue" will for sure not work!

I used the link info instead to get the Epic issue:

import com.atlassian.jira.issue.link.IssueLinkManager
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(event.issue.getId()).each {issueLink ->
    if (issueLink.getIssueLinkType().getName() == "Epic-Story Link") {
        Issue epicIssue = issueLink.getSourceObject()
    }
}

In addition, I think you should also save the changes in your issue:

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser userId = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue (userId, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

(not dispatching update events further on as you might get in an endless loop)

 

Hope this helps

Gsep Support Dec 07, 2017

Hi Marc,

Thank you for your help.

I am still having issue in getting this work. If you don't mind, could you please paste the paste the complete script.

Sorry for troubling you more and thank you in advance.

Thanks,

Suresh

Marc Minten (EVS) Dec 08, 2017

Hi Suresh,

 

The scrript is quite long and refers to a configuration (fields, workflows, ...) that is specific to our environment, so I think it is not very useful and will be difficult to understand.

Can you rather clarify what issues you still have ?

Marc

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira Software

How to prevent the propagation of unused project schemes, workflows & screens in Jira software

Atlassian ranks project attributes as the third most important factor impacting performance in the category of data. It’s not surprising, since project attributes are precisely the rules used to ma...

1,564 views 1 19
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