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
Community moderators have prevented the ability to post new answers.
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?
All of these if my assumptions above are accurate. If you elaborate more on the "randomness", maybe we can provide accurate answers to you
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think newline chars in a single line text field can indeed mess things up
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.