issues with report script and pdf export

I created a report that users will always be exporting to PDF. One requirement is having the selected data range printed on the PDF. From this post Show the current time filter on a report I know that I can show the parameter values by putting the parameter [vpInvoiceDt] in the label text property. However it displays in the form “>=08/01/2021 & <=08/04/2021” and I need a very specific format to display (ex: 01 Aug 2021 - 04 Aug 2021). I tried putting label1.labelText = {formatting date script} in the page events (Loading, Ready, Page Ready) but they all throw a “label1 is undefined error”. This script works with dashboards and on dashboard parameter value change events but doesn’t seem to work in reports and I don’t see a change event for the filter when working in a report.

Since I could not get this to work in a page event, I created a button and the click event does change the label correctly when viewing the report but when I go to Share | PDF, the updated label value does not appear in the PDF.

I also tried having the button export the PDF as well using the code from this sample:
https://www.dundas.com/support/developer/script-library/export/create-a-pdf-export

The PDF does get created but the original report page continues to have the spinner and “Working on It” message and eventually errors out with a timeout message, even though the PDF does get created correctly.

So, my questions are:

Is there a way to set a label to a filter value via script in a report that doesn’t have to be triggered by a button?

Is there a way once this label is set via script to make it so it shows up in the PDF export?

When using the Dundas provided script to have a button export a PDF, does anyone know why the screen shows the spinner and times out even though the PDF is created? (and the same exact PDF is created with the Share | PDF option with no timeout).

Thank you for any assistance you can give.

Kelly

Hi Kelly,
The label probably cannot be accessed because it is in Page Header. In a report, since items repeat several times, the controls e.g., labels have to be searched for in order to access them dynamically. You can use the below script in report ready event and that should do the job:

//search for the adapters by their friendly names
var adapters = this.getAdapters().filter(function (adapter){ return adapter.friendlyName == ‘label 1’});

//if you log variable adapters in console, you will find as many labels as there are pages in the report
adapters.forEach(function(my_label){
my_label.labelText = ‘any text’;
})
Let me now if this works for you.

Thank you so much, that worked, you have answered my first question!! The script works in the ready event, and your explanation makes a lot of sense, fantastic!! Now, do you know why it would not be reflected in the PDF?

This is what preview looks like:

but when I do Share | PDF, it does not reflect in the generated PDF what I have changed with script.

image

Hey, you can simply put the script in Before Export action of the report and that should work.

Thank you, that worked. I really appreciate all your help.

1 Like