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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the problem will be that the links are not available at the point that he needs it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
It could be the problem, but if the post function is at the end of all the post-functions in the create issue transition, wouldn't that qualify as a solution?
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, this is new for me, as I always thought that link can be accessed after the "create issue" event in the post-function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.