Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Change label color (e.g. Due Date in IssueNavigator)

Sergey Tverdokhleb February 3, 2013

Is it possible to change label color in any simple way?

For instance:

If Task has not reached it's due date, then make this 'Due' string with green color, if past due - red one.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Henning Tietgens
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.
February 3, 2013

You could create a Scripted Field (via Script Runner plugin) with following details:

  • Name e.g. "Due Date"
  • Searcher: Free Text Searcher
  • Global Context
  • Script Template: HTML

and this script:

import com.atlassian.jira.util.I18nHelper
import com.atlassian.jira.web.bean.I18nBean
import com.atlassian.jira.web.util.OutlookDate

def outlookDateManager = componentManager.outlookDateManager
def user = componentManager.jiraAuthenticationContext.getLoggedInUser()

I18nHelper i18nBean = new I18nBean(user)
OutlookDate outlookDate = outlookDateManager.getOutlookDate(i18nBean.getLocale())

def dueDate = issue.getDueDate()
def now = new Date()
if (dueDate) {
    def dueDateText = outlookDate.formatDatePicker(dueDate)
    if (now > dueDate) {
        return "<div style='color:red;'><b>" + dueDateText + "</b></div>"
    } else {
        return "<div style='color:green;'>" + dueDateText + "</div>"
    }
} else {
    return null
}

Now you could use this custom field in your issue navigator to display the colored due date.

Henning

 

jeetu August 2, 2017

Hi Henning,

we dont use outlook with jira.can u provide me modified code 

Henning Tietgens
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.
August 2, 2017

Hi jeetu,

the OutlookDateManager has nothing to do with MS Outlook. It's a class from the JIRA API to format dates.

Henning

jeetu August 2, 2017

Thanks Henning,

I am getting following error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 15: expecting ')', found ';' @ line 15, column 16.
if (now &gt; dueDate) {
^

1 error

Henning Tietgens
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.
August 2, 2017

Oh, yes, seems to be a transfer error from moving the answer from Answers to Community... I corrected the script.

Henning

jeetu August 3, 2017

Thanks Henning ,placed the code in the scripted field. i am getting the floowing error.Could you please debug the error

ERROR [customfield.GroovyCustomField]: Script field failed on issue: BISR-25, field: Dt
groovy.lang.MissingPropertyException: No such property: outlookDateManager for class: com.atlassian.jira.ComponentManager
at Script4.run(Script4.groovy:5)

Henning Tietgens
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.
August 3, 2017

Which JIRA version do you use?

jeetu August 3, 2017

I am using Jira 7.4.1

Henning Tietgens
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.
August 3, 2017

Ok, the code above is for an older version. Use this instead:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.datetime.DateTimeFormatterFactory

def formatter = ComponentAccessor.getComponent(DateTimeFormatterFactory).formatter()

def dueDate = issue.getDueDate()
def now = new Date()
if (dueDate) {
def dueDateText = formatter.format(dueDate)
if (now > dueDate) {
return "<div style='color:red;'><b>" + dueDateText + "</b></div>"
} else {
return "<div style='color:green;'>" + dueDateText + "</div>"
}
} else {
return null
}

Henning 

jeetu August 3, 2017

Thanks Henning,its working good.could you please add extra functionality to check 3 days before duedate and yellow label to it.

Henning Tietgens
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.
August 3, 2017

How about trying it by yourself? :-) It's important to learn this stuff because you have to support it for system updates and so on...

You can simply substract days from dates. So "dueDate - 3" is three days before due date. And "color:yellow" could be used for yellow.

If you have problems, paste your code and the errors you get.

Henning

jeetu August 4, 2017

Thanks Henning,have added the functionality and executed succesfully.

Henning Tietgens
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.
August 4, 2017

Well done! :-)

0 votes
ElvisDeFreitas June 3, 2016

I've created a javascript script, then my issue labels show as follows:

Selection_038.jpg

Configure it

Setup the color on the board

Selection_040.jpg

Selection_039.jpg

 

Show the labels on the cards

Selection_042.jpg

 

Use the script  bellow on tampermonkey extension (tampermonkey is a script runner extension for many browsers)

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://youratlassian.atlassian.net/secure/*
// @grant        none
// ==/UserScript==
(function($) {
    function doSomething(){
        $('*[data-tooltip*="Labels"]').each(function(){
            var css = $(this).parents('.js-detailview')
            .find('.ghx-grabber').attr('style') ;
            $(this).attr('style', css).css({
                'padding': '2px 3px',
                'color': '#303030',
                'text-shadow': '1px 1px 1px white',
                'border': '1px solid #808080'
            });
        });
    }
    setTimeout(doSomething, 1000);
    setInterval(doSomething, 1000 * 10);
})(jQuery);

 

Obs: there is a limitation, JIRA will apply only one color by card

0 votes
Sergey Tverdokhleb February 3, 2013

check if it more clear now. Thanks.

0 votes
Henning Tietgens
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.
February 3, 2013

Hi, I don't understand your question, could you provide more details? What do you mean with label?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events