Page 1 of 1

problem querying pdf_temp

Posted: Sun May 19, 2024 3:57 am
by steven
Hello all.

When trying to get the url from pdf_temp I get no result when I use $tag and yet if I hard code the SQL it works.

I don't know why?

Does anyone have any ideas?

Code: Select all

function getPDFURL($tag){
    
    $sel = "SELECT * FROM pdf_temp WHERE pdf_tag = 'nu2044536547'";	// this is the only SQL that returns a record    
    $sel = "SELECT * FROM pdf_temp WHERE pdf_tag = '$tag'";

    $tab = nuRunQuery($sel);
    $rec = db_fetch_object($tab);
    
    nudebug('URL - ', "SQL : $sel", "TAG : $tag");    	// If I paste the SQL created here into phpMyAdmin it returns a record.
    
    return $rec->pdf_file_name;
    
}

debug.PNG


Steven

Re: problem querying pdf_temp

Posted: Sun May 19, 2024 10:38 am
by kev1n
Steven,

Could you create a dump of the table pdf_temp containing that record?

Re: problem querying pdf_temp

Posted: Mon May 20, 2024 8:17 pm
by steven
Hi kev1n,

Thanks for your quick response.

I believe I know the problem.

I planned to...

Step 1 - Print a Report to the server with JavaScript using nuRunReportSave().
Step 2 - Run a Procedure to get the Report's URL (from pdf_temp) and attach this to an email and send it.

But step 1 hasn't populated pdf_temp by the time Step 2 (the Procedure) is run.

Code: Select all


function printSlips(){

    var a = [];
    var r = 'nu'+String(Math.random()).substr(-10);
    a.push(['packing-slip.pdf', r]);

    nuRunReportSave('BPS', r);
    nuRunPHPHiddenWithParams('EMAIL_ATTACHMENTS', 'attachments', a, 1);

}


Here is the code for EMAIL_ATTACHMENTS...

Code: Select all



$a = base64_decode('#attachments#');
$f = json_decode($a);
$a = [];

for($i = 0 ; $i < count($f) ; $i++){
    
    $file = $f[$i][0];
    $tag = $f[$i][1];
    
    $a[$file] = db_fetch_value('pdf_temp', 'pdf_tag', $tag, 'pdf_file_name');
    
}

$r = nuSendEmail('bob@nubuilder.com','bob@nubuilder.com','From','Content','Subject', $a, true, 'bob@nubuilder.com', 'bob@nubuilder.com');

if(!$r){
    $m = "Email Was Not Sent!";
}else{
    $m = "Email Was Sent Successfully!";
}

$j = "alert('$m');";

nuJavaScriptCallback($j);

Any idea how to make sure pdf_temp gets populated before the Procedure is run?



Steven

Re: problem querying pdf_temp

Posted: Mon May 20, 2024 11:39 pm
by kev1n
Pass a callback function to nuRunReportSave()

viewtopic.php?p=27730#p27730

I have also updated the Wiki.

Re: problem querying pdf_temp

Posted: Tue May 21, 2024 8:44 pm
by steven
Great, Thanks.


Steven

Re: problem querying pdf_temp

Posted: Tue May 21, 2024 11:34 pm
by steven
Hello again kev1n,

(sorry)

But that works great with 1 PDF.

What if I want to attach 2 PDFs to the same email?

eg.

Code: Select all

printSlips();

function printSlips(){
    nuRunReportSave('BPS2', '', cb);
    nuRunReportSave('BPS', '', cb);
}


function cb(a){
    //-- send an email
}


Steven

Re: problem querying pdf_temp

Posted: Wed May 22, 2024 4:03 am
by kev1n
To attach two PDFs to the same email in your code, you'll need to modify the callback function cb to handle storing the files and then sending the email once both files are available.

Here is how you can do it:

Code: Select all

var firstFile = null;

function printSlips(){
    nuRunReportSave('BPS2', '', cb);
    nuRunReportSave('BPS', '', cb);
}

function cb(id){
    if (firstFile === null) {
        // Store the first file in a variable
        firstFile = id;
    } else {
        // Both files are available, send the email
        const secondFile = id;
        // send email...
        firstFile = null;
 
    }
}

Re: problem querying pdf_temp

Posted: Thu May 23, 2024 11:30 pm
by steven
Thanks, that's what I needed.