Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Programatically set the colour of an Epic using ScriptRunner

Chris Preece July 2, 2020

I'm trying to programatically set the colour of an Epic on create. I'm using a Scriptrunner Post Function on the create transition

import com.atlassian.jira.component.ComponentAccessor
if(issue.issueType.name == "Epic")
{
final customFieldName = "Epic Colour"
final newValue = "ghx-label-5"
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldName }
assert customField: "Could not find custom field with name $customFieldName"
log.warn(issue.getCustomFieldValue(customField))
issue.setCustomFieldValue(customField, newValue)
log.warn(issue.getCustomFieldValue(customField))
}

It's logging (2nd log.warn) that the field value has changed, but the colour doesn't update and when I check the field value in the UI, it's unchanged.

I tried it on other transitions and adjusted the order of the post-function.

If you add the field "Epic Colour" to an edit screen, it displays and allows you to change the "ghx-label-xx" to another value. 

2 answers

1 accepted

0 votes
Answer accepted
Jack Nolddor _Sweet Bananas_
Atlassian Partner
July 2, 2020

Wich is your postfunction order? Is it at the top?

If not, try it to place your postfunction at the very begining.

 

Alternatively, you can try the following:

import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder())
Chris Preece July 3, 2020

Thanks, I played around with it some more and my original code above worked, but only if the postfunction was at the top, like you said

0 votes
Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2020

I think that the epic color is generated after the issue create step, so even if you manage to do the script to update the epic color, JIRA will overwrite with a new color.

You could try to do this after the issue creation, I tested locally and it didn't work even using a listener upon issue created event, but honestly I don't think it will worth the maintainability and effort to have this customization;

Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2020
Chris Preece July 3, 2020

Thanks very much for this. I think you're right, the colour is being set after it's possible to hook into it.

It's frustrating because Kanban is a visual process. You get information from the board outside of any text on the tickets. Colouring tickets conveys information you can absorb instantly, so not being able to programatically colourise Epics isn't optimal.

I might test some horrible workarounds... I'll reply to this post if I get anything half-working

Suggest an answer

Log in or Sign up to answer