Change filename of reports dynamically

Questions related to nuBuilder Forte Reports and the Report Builder.

Change filename of reports dynamically

Unread postby oli » Thu May 13, 2021 6:20 pm

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!
oli
 
Posts: 75
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby kev1n » Thu May 13, 2021 6:51 pm

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);   

}


Create a PHP Procedure rename_file to rename it.
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby mikevb » Sat Jun 12, 2021 11:46 pm

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?

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");
}
mikevb
 
Posts: 10
Joined: Tue Mar 20, 2018 1:37 pm
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby kev1n » Sun Jun 13, 2021 12:14 am

kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby mikevb » Sun Jun 13, 2021 12:41 pm

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.
mikevb
 
Posts: 10
Joined: Tue Mar 20, 2018 1:37 pm
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby mikevb » Tue Jun 15, 2021 10:51 am

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.
mikevb
 
Posts: 10
Joined: Tue Mar 20, 2018 1:37 pm
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby kev1n » Tue Jun 15, 2021 3:19 pm

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
kev1n
nuBuilder Team
 
Posts: 2008
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby mikevb » Tue Jun 15, 2021 9:43 pm

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"},
mikevb
 
Posts: 10
Joined: Tue Mar 20, 2018 1:37 pm
nuBuilder Version: 4.5

Re: Change filename of reports dynamically

Unread postby miasoft » Wed Sep 08, 2021 6:06 pm

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);   

}


Where should I paste this code?
Wbr, miasoft.
miasoft
 
Posts: 93
Joined: Wed Dec 23, 2020 8:58 pm


Return to Reports

Who is online

Users browsing this forum: No registered users and 1 guest

cron