It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
Hi,
I am working on a groovy script which runs when an issue is created under Epic and copies some custom field values from the epic to the created issue.
For Ex. When issue type 'Story' is created under epic, xyz CUSTOM field value from epic should be copied to Story.
But I am not able to get hold of the reference to epic in the script ( Tried and failed to get the links using IssueLinkManager class; the method getLinkCollection() returned an empty list).
Code I used:
List links = issueLinkManager.getLinkCollection(issue,user).getAllIssues()
Could some please tell how can we get reference to the linked Epic ?
Thanks,
Aravind
I had the same problem, but I did manage to get a link to the epic when the user story is created (using the new Agile board "create issue in epic")
The trick to getting this working is in the create screen for the User story, you MUST include the "Epic Link" field in the Screen configuration. This then makes the epic link custom field available in the post script function.
Then I used the following code to get to the epic...
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.Issue; CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); if (issue.getIssueTypeObject().getName() == "Story" ) { CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link'); Issue epic = issue.getCustomFieldValue(epicLink); if(epic) { issue.setFixVersions(epic.getFixVersions()); ..... } }
Chris
we also have similar need, when we create story from Epic (click on + sign) "create issue in epic" we want to copy some of the fields from Epic to story.
In Workflow- Create action, i am adding post funtion, where to add above script in post function?, i dont have any option to add groovy script in "Add Post functions"option, do i need to add in "Script post function" in that it is asking for "script file path"
so where should i put above script and give the location for this?
thanks and appreciate your help.
Can you try getting the Epic issue ID from the Story's outward links?
https://developer.atlassian.com/static/javadoc/jira/5.0.5/reference/com/atlassian/jira/issue/link/IssueLinkManager.html#getOutwardLinks(java.lang.Long)
public List<IssueLink> getOutwardLinks (Long sourceIssueId) Get links from an issue. Parameters sourceIssueId Eg. from getId() Returns List of IssueLinks
Hi Tarun and Jamie,
Thanks for your responses.
My script is at the end of all post functions but still the issue exists. Plus I have tried calling getOutwardLInks() also ( as per definition of getLinkCollection () gives both ingoing and outgoing issue links )
Thanks
Links are created after the issue is created, so you don't have the link. Maybe you can get information about the Epic within the request, like in my answer here: https://answers.atlassian.com/questions/266063/groovy-script-error-in-jira-6-1-missingpropertyexeption, but I don't have tested this.
Tarun
can you please help me with this
we also have similar need, when we create story from Epic (click on + sign) "create issue in epic" we want to copy some of the fields from Epic to story.
In Workflow- Create action, i am adding post funtion, where to add above script in post function?, i dont have any option to add groovy script in "Add Post functions"option, do i need to add in "Script post function" in that it is asking for "script file path"
so where should i put above script and give the location for this?
thanks and appreciate your help.
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreCan a new-to-agile team survive and thrive in a non-agile culture? If so, what advice would you give to those trying to be agile in a non-agile culture? What's the key(s) to success? Share your thoug...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.