Page 1 of 1

Change filename of reports dynamically

Posted: Thu May 13, 2021 10:50 am
by oli
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!

Re: Change filename of reports dynamically

Posted: Thu May 13, 2021 11:21 am
by kev1n
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.

Re: Change filename of reports dynamically

Posted: Sat Jun 12, 2021 4:16 pm
by mikevb
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");
}

Re: Change filename of reports dynamically

Posted: Sat Jun 12, 2021 4:44 pm
by kev1n

Re: Change filename of reports dynamically

Posted: Sun Jun 13, 2021 5:11 am
by mikevb
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.

Re: Change filename of reports dynamically

Posted: Tue Jun 15, 2021 3:21 am
by mikevb
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.

Re: Change filename of reports dynamically

Posted: Tue Jun 15, 2021 7:49 am
by kev1n
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

Re: Change filename of reports dynamically

Posted: Tue Jun 15, 2021 2:13 pm
by mikevb
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"},

Re: Change filename of reports dynamically

Posted: Wed Sep 08, 2021 10:36 am
by miasoft
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?