I have used a code I found to create a scripted custom field with scriptrunner that shows me the Epic Link in a issue and also a Sub-Task.
I now want the custom field to have the epic color as the background color, because we use the color to identify different categories of topics (to save a column on the dashboard we use for stand up meetings).
Currently the output of the field is:
Epic Name
I want:
The code I used is:
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 cfManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = cfManager.getCustomFieldObjectByName('Epic Link');
CustomField epicName = cfManager.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 '<a href=myURL'+ epic +'>'+ epicNameString +'</a>'
Thank you a lot!
At first, I was going to say you can't do that ... but with a bit of perseverance ... I think I found something that might work for you:
Try this:
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 cfManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = cfManager.getCustomFieldObjectByName('Epic Link');
CustomField epicName = cfManager.getCustomFieldObjectByName('Epic Name');
CustomField epicColor = cfManager.getCustomFieldObjectByName('Epic Colour');
//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.issueType.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)
String epicColorVal = epic.getCustomFieldValue(epicColor)
return """<a class="aui-label $epicColorVal" href="/browse/$epic">$epicNameString</a>"""
Changed or added lines are bold & underlined
Note, you don't need to put your full url... just start with "/browse" and that will start at the root of your site. You may need to include /jira/browse if you have multiple apps/instances on the same server. Also using triple quoted lines for HTML makes things much easier to manage and read than to use single quotes and +
Thanks for the reply!
The code makes the link look like the Epic Link, but it always uses the same color:
I will try to figure out how the aui-label gets its color.
Also thanks for the note regarding the shorter url and the advice with the triple quoted lines. I am not a programmer so anything that makes it easier for me helps!
_____________________________________________________
As a quick-and-dirty solution I figured out how to change the background color of the html links, doesn't exactly look like the Epic Link, but doesn't matter.
Now I need to find the hex values for the 15 colors. For Cloud I got them, but we are running Server.
Code:
return """<a href="/browse/$epic" style="color:#FFFFFF; background-color:#42526E">$epicNameString</a>"""
How would I go on and code this once I have all 15 hex codes for the 15 colors?
I could to 15 times
if (epicColorVal == "ghx-label-1")
return """<a href="/browse/$epic" style="color:#FFFFFF; background-color:#42526E">$epicNameString</a>"""
but I believe there must be a better way.
Thank you again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried this right within the context of the issue?
I think the ghx-label-1 class has to exist in the css available at any given context.
Jira loads css and js resources dynamically based on what it determines is needed based on what will be viewed in the current context.
So if you ran that script just in the scripted field "preview" screen, then the class is not available.
But when viewing an issue, then the class should be there should apply a color.
View an issue with an epic and inspect the epic name label in the chrome developer panel. You should be able to view how the color is applied.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.