Changing the (Base) report filename

In Base, I have a simple db setup with a form for entering data. My form has a single press button which opens the current record in a report. From the report (Writer) I usually select File > Send > Email as PDF.

I notice the report has a filename based on the underlying report filename, plus index. I’d like to specify exactly the report filename. Is that possible please?

My database is a simple customer, order type affair. The reports are ‘invoices’ and so I’d like the Writer document filename to include the invoice number.

My press button macro has access to the invoice ref:

invoice_ref = oForm.getString(oForm.findColumn("invoice_ref"))

I open the report like this:

ThisDatabaseDocument.ReportDocuments.getByName("Invoice").open

I tried this but the Name filed is read-only:

nHandle = ThisDatabaseDocument.ReportDocuments.getByName("Invoice")
nHandle.name = "Invoice_" + invoice_ref

Also tried perusing the API docs, but got a little lost!
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1sdb_1_1XSubDocument.html

Any help much appreciated.

Hello,

Yes you can do this but it will cost more in potential problems than it is worth. It appears you objective here is to not have to enter in the invoice number when the email is generated. It would be surprising if this wasn’t already on the document itself.

You can change a report name in a macro with:

 myReports = ThisDatabaseDocument.ReportDocuments.getByName("YOUR_REPORT_NAME")
 sNewName = "Invoice_" + invoice_ref
 myReports.rename(sNewName)

Now if this is done, the next time this is run the report name is incorrect. So before changing the name it should be saved and changed back after running the report. Save the name with:

 sName = myReports.Name

But the problems are not over. Reports are saved while LO is open in the /tmp directory and the Registry is also involved. Each time a report is run there is an incremental number appended on to the name. This can probably be overcome by emptying the /tmp directory but not certain as to the repercussions it may have on the Registry.

My suggestion would be to test some of this and see the problems presented. Have done this testing and can’t see entering a name manually being tougher than the potential for problems.

Well you answered my question on how to rename the report prior to opening in Writer, so thank you for that. I share your concerns about the automatic index that’s appended. I need to decide if I can live with that or like you say, just Save As in Writer and manually name the file/pdf.

A thought here, change this line:

sNewName = "Invoice_" + invoice_ref

to:

sNewName = "Invoice_" + invoice_ref + "_"

and the invoice # will remain intact within the underscores. This indexing will occur after the ending underscore. Just a suggestion.

Have found an easier, safer method for this. It is part of this answer → How to print a base report and send it by mail (mailmerge)