Using field value in PDF filename when exporting a grid

Is there any way to use a field from within the grid as part of the filename for the PDF export? I used the following

sc_set_pdf_name = “report no {id}.pdf”;

in ‘onApplicatioanInit’ but the field value is simply ignored. The resulting filename is report no .pdf

I also tried using the

sc_set_export_name (“pdf”, “report no {id}.pdf”);

but I got the same result. The {id} value is not added to the filename of the exported PDF.

Any ideas on how to achieve this?

Possibly because it is all in quotes implying a literal value? “report no “.{id}.”.pdf” or make the entire thing a variable. $title=“report no “.{id}.”.pdf” ; sc_set_pdf_name=“pdf”,’$title’); (the ’ on the title may not be needed)

Unfortunately, both options return errors when running the script.

Even when trying to create a simple variable for the {id}, on the export that variable is simply ignored, and the PDF is saved without the {id} in the filename.

$title={id};
sc_set_export_name (“pdf”, “$title.pdf”);

When trying the following

$title={id};
sc_set_pdf_name=“pdf”,’$title’);

I get Parse error : syntax error, unexpected token “,” in /Applications/Scriptcase/v9-php81/wwwroot/scriptcase/app/ClubAdmin2/grid_new/index.php on line 1110

I was able to achieve this with no problem in a PDF report by using

$pdf->Output(“Report no “.{id}.”.pdf”,‘I’);

and this was placed in the Layout, Code of the PDF report. However, for the grid export to PDF nothing I tried seems to work.

FINALLY. I found a solution that works for the grid export to PDF.

In order to use a custom name containing a field value, for the PDF export from a grid, I did the following:

  1. I created a parameter in an SQL Command:

FROM
tabel_name

WHERE
id = [number]

Than, in the Events, onApplicationInit I added: sc_set_pdf_name = “Report no [number].pdf”;

This way when I export a PDF by using a grid, the filename of the exported file looks like Report no 2.pdf

1 Like