Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

inheriting epic name to subtask

This isn't really a question, more of something we did at our company to be able to tie Epics, stories, and subtasks to the epic.

We did this by using script runner and creating a scripted field, and then for the scripted field we used this code:

 

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();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
CustomField epicName = customFieldManager.getCustomFieldObjectByName('Epic Name');
//This is where we store the issue that is linked to the epic.
Issue issue_linked_to_epic
/* determine if this is an epic, if so, return the epic link name */
if (issue.issueTypeObject.name == "Epic"){
	return issue.getCustomFieldValue(epicName)
}
/*determine if this is a subTaskIssueTypes(), if so, set the parent to the issue linked to the epic */
Issue issueParent = issue.getParentObject()
if (issueParent == null){
	issue_linked_to_epic = issue
} else {
	issue_linked_to_epic = issueParent
}
/* get epic link */
Issue epic = issue_linked_to_epic.getCustomFieldValue(epicLink)
if (epic == null){
	return null
}
String epicNameString = epic.getCustomFieldValue(epicName)
return epicNameString

 

Now we have a single custom field, "Epic Name for Reporting" that we can use in Filters to tie subtasks, stories, and epics together.

5 answers

Thank You!

It's really usefull script.

I builded my own, based on your idea, to extract Epic ID from Epic Link smile

 

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;

if (issue.issueTypeObject.name == "Story")
{
    CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
Issue epic = issue.getCustomFieldValue(epicLink)
if (epic == null)
    {
    return null
}
String nazwaID = epic.getKey()
return nazwaID
}
return null
 

 

 

Hey J,

 

If you cast the Object to an Issue, it will work.

 

Try this: Issue epic = (Issue) issue_linked_to_epic.getCustomFieldValue(epicLink)

Nathan, in 7.1 your script gives a couple of errors. One of them I was able to fix but the second one I'm not sure about. 

The second one is this line: Issue epic = issue_linked_to_epic.getCustomFieldValue(epicLink)

and scriptrunner now says Cannot assign value of type java.lang.object to variable of type com.atlassian.jira.issue.Issue

Anyway I'm just not sure what to change this to, have you updated to 7.1 yet and if so what was the change that was needed?

I hadn't had time to get back to this since this original posting but your fix did the trick! 

 

Many thanks!

Hi it seems it doesn´t work with the server version, for e. g. the issue object is always empty if it´s an 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();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
CustomField epicName = customFieldManager.getCustomFieldObjectByName('Epic Name');
//This is where we store the issue that is linked to the epic.
Issue issue_linked_to_epic
/* determine if this is an epic, if so, return the epic link name */
if (issue.issueTypeObject.name == "Epic"){
return issue.getCustomFieldValue(epicName)
}
/*determine if this is a subTaskIssueTypes(), if so, set the parent to the issue linked to the epic */
Issue issueParent = issue.getParentObject()
if (issueParent == null){
issue_linked_to_epic = issue
} else {
issue_linked_to_epic = issueParent
}
/* get epic link */
Issue epic = (Issue) issue_linked_to_epic.getCustomFieldValue(epicLink)
if (epic == null){
return null
}
String epicNameString = epic.getCustomFieldValue(epicName)
return epicNameString

Hello ,

I have run the script, it gives me the following error:
Error
null
java.lang.NullPointerException.

Please, can someone tell me how to fix it ...
I have Jira server 8.8

Thanks in advance

Suggest an answer

Log in or Sign up to answer
TAGS

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