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.
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())
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
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.
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
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.