Page 1 of 2
How can I add a button for sending a report by email?
Posted: Wed Apr 21, 2021 10:24 am
by absalom
Hi have a button on a form for triggering the nuRunReport("FR0") Javascript command, and it works fine for building and opening the PDF report. Could I have a second button for building and sending the PDF report by email?
When opening the console and typing nuEmailReportAction("FR0")
I get:
Code: Select all
Uncaught ReferenceError: nuEmailReport is not defined
nuEmailReportAction https://gestion.psychologie-brest.fr/core/nuform.js?ts=20210421101738:2870
<anonymous> debugger eval code:1
debugger eval code:2870:2
Re: How can I add a button for sending a report by email?
Posted: Wed Apr 21, 2021 11:27 am
by kev1n
Hi,
nuEmailReport () doesn't seem to exist in nuBuilder 4/4.5. and I didn't find any other function that would generate a report and send it.
So you would have to save the report first with
nuRunReportSave()
and the send it with the
nuSendEmail PHP function.
Let me know if that works for you.
Re: How can I add a button for sending a report by email?
Posted: Wed Apr 21, 2021 4:17 pm
by kev1n
Example:
JavaScript:
Code: Select all
nuRunReportSave('FR0', null, reportCreated);
function reportCreated(filename, id) {
nuSetProperty(''filename', filename);
nuRunPHPHidden('sendemail',0);
}
Then create a PHP Procedure with code
sendemail and retrieve the filename in the PHP code and send the email:
$file = "#filename#";
Code: Select all
nuSendEmail('to@test.com','from@test.com','From','Content','Subject', [$file], true)
(Latest nurunpdf.php and nuajax.js required from
Github)
Re: How can I add a button for sending a report by email?
Posted: Sat May 29, 2021 6:14 pm
by oli
Hello,
I tried to follow this instruction to send a report via e-mail. The Mail will be sent out but
without attachment of the report. The report is created properly and available in the temp dir.
In the same procedure I'd like to store the file with a new name in a local folder - unfortunately I get following error message and I couldn't find any reason for it.
Here's the value of both variables containing the filenames:
Code: Select all
$file = C:\wamp64\www\bts-sandbox1/temp/nupdf_60b266a01e75190.pdf
$file_new = Z:\temp\Angebot-Nr-1012.pdf
This is the procedure (sendemail):
Code: Select all
$file = "#filename#"; // get Filename
$angebot = "#auf_nummer#"; // get Order Number
$file_new = $file_new . '\Angebot-Nr-' . $angebot . '.pdf'; // prepare new filename
nuSendEmail('xxxxx@web.com','xxxxxxxx@gmail.com','From','Content','Subject', [$file], true); // Send E-Mail to xxxx@gmail.com
// Get folder to save new the file
$sql = 'SELECT inp_dir_angebote FROM systemsettings LIMIT 1';
$result = nuRunQuery($sql);
if (db_num_rows($result) > 0){
while($row = db_fetch_row($result)){ // Get Folder from systemsettings table
$dir_angebot = $row[0];
}
}else{
$dir_angebot = 'c:'; // no folder defined
}
$file_new = $dir_angebot . $file_new; // Folder + Filename
nuDebug($file);
nuDebug($file_new);
copy($file, $file_new); // Copy Report
This is the error message when I try to copy the report :
Code: Select all
Call Stack
# Time Memory Function Location
1 0.0004 448576 {main}( ) ...\nuapi.php:0
2 0.0195 696032 nuRunPHPHidden( ) ...\nuapi.php:67
3 0.0260 1538928 nuEval( ) ...\nucommon.php:421
4 0.0268 1548424 eval( '$file = "C:\\wamp64\\www\\bts-sandbox1/temp/nupdf_60b264b8592bbc4.pdf"; // get Filename
Can someone help me in this regard please?
Thanks a lot.
Oli!
Re: How can I add a button for sending a report by email?
Posted: Sat May 29, 2021 7:22 pm
by kev1n
nuSendEmail deletes the files after sending.
Re: How can I add a button for sending a report by email?
Posted: Sat May 29, 2021 7:50 pm
by oli
kev1n wrote:nuSendEmail deletes the files after sending.
I put nuSendEmail at the end of the procedure but without success:
Code: Select all
( ! ) Warning: copy(Z:\temp\Angebot-Nr-1014.pdf): failed to open stream: No such file or directory in C:\wamp64\www\bts-sandbox1\core\nucommon.php(1302) : eval()'d code on line 21
Also the report is still not attached to the e-mail?!
Re: How can I add a button for sending a report by email?
Posted: Mon May 31, 2021 8:36 am
by kev1n
Add some debugging code like file_exists () to track down the error.
Re: How can I add a button for sending a report by email?
Posted: Mon May 31, 2021 9:06 am
by oli
Hi kev1n,
copy to Z: (a windows share) was not possible since PHP seems to have an issue with copying files to shares. To copy the file to the local drive was possible.
But I still cannot send the report via e-mail.
I get the E-Mail, but no file is attached to it.
I'm using following path to the report file in my script and file_exists gives me "1" as a result and I can see the file in the temp-directory.
$file = C:\wamp64\www\bts-sandbox1/temp/nupdf_60b48826b2493d3.pdf
Code: Select all
nuSendEmail('gaigalat@web.de','computer@gaigalat.de','From: Admin','Test E-Mail from ....','Your Order', [$file], true);
I have no idea how to find out why the file is not attached to the e-mail.
Do you have any idea?
Re: How can I add a button for sending a report by email?
Posted: Mon May 31, 2021 1:43 pm
by oli
There's also a JavaScript function available (nuEmailReportAction) but I couldn't find any detailed documentation about it.
Could this maybe solve my problem?
Re: How can I add a button for sending a report by email?
Posted: Mon May 31, 2021 3:40 pm
by oli
Just to add some more information that might be helpful to find a solution or to find out what I am doing wrong:
- On the form I created a run object (Button) which is calling my report
- To this run object I added an "onclick" event with following JavaScript Code:
Code: Select all
nuRunReportSave('rep_angebot', null, reportCreated);
function reportCreated(filename, id) {
nuSetProperty('filename', filename);
nuRunPHPHidden('sendemail',0);
}
- I created a procedure "sendemail" containing following PHP code:
Code: Select all
$file = "#filename#"; // get Filename
if(file_exists($file)){
nuSendEmail('xxxxxxx@gmail.com',xxxxxxxx@xxxxxxx.de','From: Admin','Test E-Mail from ....','Your Order',[$file],true); // Send E-Mail
}else{
nuDebug('Cannot send ' . $file);
}
Following results:
- no entry in nuDebug results
- E-Mail has been sent with the content
- Report-File "$file" is NOT attached to the e-mail (even it exists on the server)
Is there anything I can do to get more information or is there anything configured wrongly?