Colouring comments

Hi!

I have created custom field with javascript to get all the comments of the issue.

I have colouring logic which I am applying with the javascript:
If issue is in any other status than “in progress”, keep all the comments in black
If comment was added during past 7 days, mark the comment in green
If last comment was added more than past 7 days ago, mark the comment red
if not last comment & added more than past 7 days ago, mark the comment black

Problem:
Comment will stay green even when the 7 days has passed when no new comments have been added. This is because eazyBi only imports when something has changed - since no new comments have been added, it doesn’t re-import it & run it through javascript. (Javascript itself works, when I go to test it, the green color is replaced with red, as it should be. And custom field on the bottom displays correct value. It just isn’t visible in the report)

I wanted to use: check_calculated_value = true
But this isn’t available for javascript custom fields.

What other options do I have to make it work?

Thanks in advance

Hi @Krisseliine_Part,

A warm welcome to the eazyBI community :partying_face: !

You are correct. The parameter check_calculated_value = true doesn’t work for JavaScript calculated custom fields.

An approach I can think of right now is importing all the comments with HTML formatting placeholders for each comment. For example, each separate comment is inside its own <p></p> tags. The imported comment property then could return results similar to the one below in plain text:

<p>Curabitur blandit tempus ardua ridiculus sed magna.</p>
<p>Magna pars studiorum, prodita quaerimus.</p>
<p>Curabitur blandit tempus ardua ridiculus sed magna.</p>

Next, import the last commend date as a JavaScript calculated custom field. See an example here - JavaScript calculated custom fields.

Now you can define a new calculated measure that will compare the last comment date to the current date and color the last comment accordingly with HTML style element. See the suggested formula below:

CASE WHEN
  NOT IsEmpty([Measures].[Issue All comments])
  AND
  -- how old in days is the comment?
  DateDiffDays(
    [Measures].[Issue Last Comment Date],
    'now'
  ) < 2
THEN
  -- replace the last line/comment with the comment wrapped in a <span> element and color it green
  Replace(
    [Measures].[Issue All comments],
    -- find the last line (comment)
    ExtractString(
      [Measures].[Issue All comments],
      '.*</p>\z',
      0
    ),
    -- wrap the last line/comment within a <span> element and color it
    '<span style="color:green">'||
    ExtractString(
      -- find last line
      [Measures].[Issue All comments],
      '.*</p>\z',
      0
    )
  )
ELSE
  -- replace the last line/comment with the comment wrapped in a <span> element and color it red
  Replace(
    [Measures].[Issue All comments],
    ExtractString(
      -- find last line
      [Measures].[Issue All comments],
      '.*</p>\z',
      0
    ),
    '<span style="color:red">'||
    ExtractString(
      -- find last line
      [Measures].[Issue All comments],
      '.*</p>\z',
      0
    )
  )
END

Update the formula to consider the correct issue properties and duration in days from the last comment date. Use the “HTML” formatting option for the calculated measure. Please see an example below with the two JavaScript calculated properties and the calculated measure:

Best,
Roberts // support@eazybi.com