Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Change filename of reports dynamically
Change filename of reports dynamically
HI,
is there a way to change the filename of a report based on field values?
e.g. creating a report and the name of the report should contain the value of a date field.
Thanks in advance.
Oli!
is there a way to change the filename of a report based on field values?
e.g. creating a report and the name of the report should contain the value of a date field.
Thanks in advance.
Oli!
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Change filename of reports dynamically
You could rename the report after saving.
Create a PHP Procedure rename_file to rename it.
Code: Select all
nuRunReportSave('FR0', null, reportCreated);
function reportCreated(filename, id) {
nuSetProperty(''filename', filename);
nuRunPHPHidden('rename_file',0);
}
-
- Posts: 14
- Joined: Tue Mar 20, 2018 5:07 am
Re: Change filename of reports dynamically
Hi Kevin
I use exactly your method and it works fine IF the report has one or two pages. I want to use it with a report that generates 10-15 pages and then it fails.
It takes approx 5 seconds to generate it. After the script is done I can find a new entry in the table pdf_temp and the PDF file is generated in the directory /temp. The php-script that I use to rename the file doesn't run.
I believe that generating the report takes too long and therefore it doesn't finish. I tested the whole thing by only changing the report code for a one-page-report and that works fine.
How can I tweak the code that also big reports can be generated and renamed with that process?
I use exactly your method and it works fine IF the report has one or two pages. I want to use it with a report that generates 10-15 pages and then it fails.
It takes approx 5 seconds to generate it. After the script is done I can find a new entry in the table pdf_temp and the PDF file is generated in the directory /temp. The php-script that I use to rename the file doesn't run.
I believe that generating the report takes too long and therefore it doesn't finish. I tested the whole thing by only changing the report code for a one-page-report and that works fine.
How can I tweak the code that also big reports can be generated and renamed with that process?
Code: Select all
nuRunReportSave('TEST', null, reportCreated);
function reportCreated(filename, id) {
nuSetProperty('filename', filename);
nuRunPHPHidden('display_tk_abend',0);
}
Code: Select all
$pdfsrc = "#filename#";
if(file_exists($pdfsrc)){
rename($pdfsrc,$pdfdst);
nuDisplayError("Success");
}else{
nuDisplayError("Error");
}
-
- Posts: 14
- Joined: Tue Mar 20, 2018 5:07 am
Re: Change filename of reports dynamically
That doesn't seem to be the problem; I checked the server settings. I can successfully run the report with [Run Report] or with my own run button.
nuRunReportSave() also creates the report as expected and I can find it in /temp. It just doesn't execute my php and therefore the report is not moved to the destination directory.
I now created a very basic Fast Report using the same SQL and that one seems to work very well, producing 20 pages and moved to the destination directory in no time. It probably doesn't like something I did in the Report Designer. I'll recreate the same design from scratch and see what happens. I let you know.
nuRunReportSave() also creates the report as expected and I can find it in /temp. It just doesn't execute my php and therefore the report is not moved to the destination directory.
I now created a very basic Fast Report using the same SQL and that one seems to work very well, producing 20 pages and moved to the destination directory in no time. It probably doesn't like something I did in the Report Designer. I'll recreate the same design from scratch and see what happens. I let you know.
-
- Posts: 14
- Joined: Tue Mar 20, 2018 5:07 am
Re: Change filename of reports dynamically
Yes it must have been something in the report builder. I rebuilt the exact same report from scratch and that one works with nuRunReportSave(). The original report runs fine when run by a run button, but fails with nuRunReportSave().
Problem solved, but I don't know why. When I get some time I can maybe compare the database entries of these two reports (data blob from report builder). They should be the same but they must have a diff somewhere.
Problem solved, but I don't know why. When I get some time I can maybe compare the database entries of these two reports (data blob from report builder). They should be the same but they must have a diff somewhere.
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Change filename of reports dynamically
It would certainly be interesting to compare the report JSONs by using a diff viewer like https://www.diffnow.com/
Table: zzzzsys_report, column sre_layout
Table: zzzzsys_report, column sre_layout
-
- Posts: 14
- Joined: Tue Mar 20, 2018 5:07 am
Re: Change filename of reports dynamically
Thank you Kevin, I got the data. It's very obvious: I used these dashes with a very small font to create a very thin line. It works great and it marks on the paper where we need to cut the page. Manually running the report is fine, but somehow the nuRunPHPHidden() after nuRunPHPSave() doesn't like that. Because I cloned the report several times with small variations, all the reports with these dashes don't execute nuRunPHPHidden() after nuRunPHPSave(), but when run manually they all work fine. By creating a new report from scratch, I forgot to create this line and that's why it works.
Code: Select all
{"top":30,"left":30,"bottom":260,"right":30,"width":210,"height":297,"paper":"A4","orientation":"P","groups":[{"sortField":"Detail","sortBy":"a","sections":[{"id":"","top":110,"height":395,"label":"Detail Header","page_break":0,"margins":6,"color":"#FFFFFF","objects":[{"id":"obj1001","objectType":"label","backgroundColor":"white","borderColor":"black","borderWidth":"o","fieldName":"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------","fontColor":"black","fontFamily":"Helvetica","fontSize":"2","fontWeight":"","format":"","textAlign":"left","image":"","group":0,"section":0,"left":40,"top":1,"height":"2","width":760,"zIndex":124,"minRows":0,"maxRows":"1","selected":0,"name":"obj1001"},
-
- Posts: 156
- Joined: Wed Dec 23, 2020 12:28 pm
- Location: Russia, Volgograd
- Has thanked: 32 times
- Been thanked: 7 times
- Contact:
Re: Change filename of reports dynamically
Where should I paste this code?kev1n wrote:You could rename the report after saving.
Code: Select all
nuRunReportSave('FR0', null, reportCreated); function reportCreated(filename, id) { nuSetProperty(''filename', filename); nuRunPHPHidden('rename_file',0); }
Wbr, miasoft.