It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unwanted values populating in a custom jira report in PDF format

While generating a custom report in PDF format a field is populating unwanted values. Values which are not present in the task. 

A custom field is simply not selected at all. (Field is not used). It is not a mandatory field. So a default value is being populated. But that is not the desired output.

Is there any way to keep a hyphen (-) instead of populating default values.

 

 

1 answer

1 accepted

0 votes
Answer accepted

Because your question is tagged with "midori", I suspect you are using the Better PDF Exporter app.

If so, I'm a developer working on it and happy to help, but I need more details:

  1. Can you share an output sample that demonstrates the problem?
  2. Can you share the template code?
  3. What is the custom field type of the problematic field?
  4. How is that default value populated to the field?

Hi Aron,

Thank you for getting back!

Yes, we use Better PDF Exporter app.

Recovery timeline is the custom field.

"Recovery Timeline" is EMPTY - is the condition in the query.

Example of what the value is in the below picture

Capture.PNG

as per the query, the value of the field should be empty in the pdf file

but it's populating current date of the system. If the above condition is used in the query. 

Capture1.PNG

If that condition is not being used it is populating Recovery timeline date of the previous project that is rendered in the PDF.

But the expected output is a hyphen (-) or a blank column.

#set($recoveryTimeline = $customFieldManager.getCustomFieldObjectByName("Recovery Timeline"))
#set($recoverytimelinevalue = $issue.getCustomFieldValue($recoveryTimeline))

<fo:block>
$userDateTimeFormatter.withStyle($dateTimeStyle.DATE).format($recoverytimelinevalue)
</fo:block>

is the format in which I'm calling the value.

Please let me know if you need more details.

It's just a quick idea, but if you can find a good condition to decide if you want to see the actual value or a hyphen in the output, then of course you could just:

#set($recoverytimelinevalue = $issue.getCustomFieldValue($recoveryTimeline))
<fo:block>
#if(... your condition comes here ...)
## export the value
$userDateTimeFormatter.withStyle($dateTimeStyle.DATE).format($recoverytimelinevalue)
#else
## export the hyphen
-
#end
</fo:block>

So, the question what would be the correct condition?

As a dumb one, I could imagine that you check if the $recoverytimelinevalue holds a time value that is older than an hour. If it is not, then it is the "current date", so you render the hyphen. Otherwise you render the actual value.

Like P likes this

You are not dumb at all. 

It works like a charm!

Thank you so much Aron :)

Hi Aron,

I still have issues with the code I wrote. Can you please help me out.

<fo:table-row>
<fo:table-cell padding="1mm" border-width="1mm" border-style="solid">
<fo:block font-weight="bold"> Recovery Timeline </fo:block>
</fo:table-cell>
#set($recoveryTimeline = $customFieldManager.getCustomFieldObjectByName("Recovery Timeline"))
#set($recoveryimelinevalue = $issue.getCustomFieldValue($recoveryTimeline))
#if($recoveryimelinevalue == $currentdate - 1)
<fo:table-cell padding="1mm" border-width="1mm" border-style="solid" number-columns-spanned="7">
<fo:block space-before="1mm">
<fo:block>
-
</fo:block>
</fo:block>
</fo:table-cell>
#else
<fo:table-cell padding="1mm" border-width="1mm" border-style="solid" number-columns-spanned="7">
<fo:block space-before="1mm">
<fo:block>
$userDateTimeFormatter.withStyle($dateTimeStyle.DATE).format($recoveryimelinevalue)
</fo:block>
</fo:block>
</fo:table-cell>
#end
</fo:table-row>

This is the block in the custom report I have issues with. 

I am seeing that the recovery timeline value is sometimes populating the value of the old project.

For example in the report

there is an xyz project with recovery timeline value 31/Dec/19 which is populated in the first column

and a project abc which doesn't have any recovery timeline value specified in the issue

but it's still showing 31/Dec/19

I am not sure why.

In the Velocity language, you cannot assign NULL to a variable. When you try that, the variable will keep its previous value!

For example:

#set($foo = 2)
#set($foo = $bar) ## if bar is null, then this code will not do anything

## at this point foo still equals to 2!

So, the trick is to assign an empty string and do a check, something like this:

#set($recoveryimelinevalue = "") ## we assign an empty string
#set($recoveryimelinevalue = $issue.getCustomFieldValue($recoveryTimeline))
#if($recoveryimelinevalue != "")
## in this block we can know that the custom field had an actual value
#else
## the custom field value was NULL
#end

Can you follow me?

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you