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

custom field randomly disappears

Alexander August 25, 2015

Hi, I created a new calculated custom field which calculates:
For all users who worked on issue: if issue in closed status - user influence (user TT / Issue TT), else user TT.

Here is some code:

<!-- @@Formula:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.worklog.Worklog;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;

import java.sql.Timestamp;
import java.util.*;
import java.text.SimpleDateFormat;

String getUserBudget(issue)
{
    Issue currentIssue = issue.getIssueObject();
    Double issueTT = 0;
    Timestamp dateValue = currentIssue.getDueDate()    
    String result = "";
    
    if (null != dateValue && null != currentIssue.getTimeSpent())
    {
         issueTT += currentIssue.getTimeSpent().doubleValue() / 3600;
        userCBValues = new HashMap();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd");        
        worklogs = ComponentAccessor.getWorklogManager().getByIssue(currentIssue);
        Double userCBValue = 0;
        Double userTT = 0;      
        
        for (Worklog worklog : worklogs)
        {
            userTT = worklog.getTimeSpent().doubleValue() / 3600;
            if (userCBValues.containsKey(worklog.getAuthor()))
            {
                userTT += userCBValues.get(worklog.getAuthor());
            }
            userCBValues.put(worklog.getAuthor(), userTT);
        }
        
        if (currentIssue.getStatusObject().getName().equals("Closed"))
        {
            for (String userKey : userCBValues.keySet())
            {
                userCB = userCBValues.get(userKey) / issueTT;
                userCBValues.put(userKey, userCB);
            }
        }
        for (String userKey : userCBValues.keySet())
        {
            result += simpleDateFormat.format(dateValue) + "," + userKey + "," + userCBValues.get(userKey) + "\n";
        }
    }
    return result;
}
String result = getUserBudget(issue);
if (!result.equals(""))
{
    return result;
}
-->

When I view custom field values on the issue navigator it sometimes randomly disappears on different issues. Atlassian log file is empty.

I found this ticket https://innovalog.atlassian.net/browse/JMCF-113 - didn't help.
JIRA - 6.4.4
JMCF - 1.6.1

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
GabrielleJ
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 26, 2015

How random is it? Like for a particular issue, there is value on it now then when you refresh it disappear? Or is it that some tickets have value on it, some tickets don't? 

  • Assuming it's the 1st. It might be something in your code that is the cause. Where do you put this Calculated field? Is it being calculated everytime the issue is viewed? or during a transition and save the results in a custom field?
  • It it's the 2nd, it might be the issues that don't have this custom field does not have any value on it. Note that Custom Fields that do not have a value won't appear on the View Screen. 

All of these if my assumptions above are accurate. If you elaborate more on the "randomness", maybe we can provide accurate answers to you smile

Alexander August 26, 2015

The first. It appears randomly on refreshes (Field can have value over 20 refreshes, but on the next one - it disappears - null value). This field on a view screen, calculates every time. I can't find a mistake in code - that's why I asked a question here.

David _old account_
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 27, 2015

So what you're saying is that, if you stay on the view issue screen for an issue, you see "42" as the value of the custom field, and if you hit refresh regularly, at some point the custom field will disappear from the view issue screen, right?

Alexander August 27, 2015

you are right David, and I can reproduce disappearing moment with eazybi data import, or may be while re-index too. I asked Atlassian Support, thank you for suggestion.

Alexander September 21, 2015

didn't help... still disappearing

0 votes
David _old account_
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 25, 2015

I assume you re-index JIRA after creating/modifying the custom field? Because the Issue Navigator relies solely on the index (unlike the view issue screen which recomputes calculated fields).

Also, for better readability, you should return null when your field is empty.

David

Alexander August 25, 2015

I made re-index.

David _old account_
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 25, 2015

And the field always appears on the view issue screen? Then it looks like a JIRA issue. I wonder if the carriage return in the field value could have something to do with it.

Alexander August 25, 2015

on some issues I don't see field value, after refresh - on a different issues. I don't think that \n can do smth... We need it for calculating formulas (in eazybi).

David _old account_
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 25, 2015

I kind of remember seeing that behavior before, and it was totally unrelated to JMCF. But I can't remember whether it was a bug in a particular version of JIRA or a bug with another plugin. You should definitely contact Atlassian support. You did not answer my question: do you always see the field _on the View Issue Screen_ (not the issue navigator)?

David _old account_
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 25, 2015

Oh, and if you replace your formula with a simple constant string, does it start working reliably? If it does, then something must be wrong in your formula. If it doesn't, then it has nothing to do with JMCF.

MattS
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 26, 2015

I think newline chars in a single line text field can indeed mess things up

Alexander August 26, 2015

David, I replaced the result string with current date, user from worklog and 42 - still disappears. Matt, I replaced newline with space - didn't help.

David _old account_
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 27, 2015

So it is not an issue with the custom field, but with either JIRA or another plugin. You should definitely contact Atlassian, after double-checking that you indeed don't get any error in atlassian-jira.log.

TAGS
AUG Leaders

Atlassian Community Events