Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

problem querying pdf_temp Topic is solved

Questions related to nuBuilder Forte Reports and the Report Builder.
Post Reply
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

problem querying pdf_temp

Unread post 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
You do not have the required permissions to view the files attached to this post.
A short post is a good post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: problem querying pdf_temp

Unread post by kev1n »

Steven,

Could you create a dump of the table pdf_temp containing that record?
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: problem querying pdf_temp

Unread post 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
A short post is a good post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: problem querying pdf_temp

Unread post by kev1n »

Pass a callback function to nuRunReportSave()

viewtopic.php?p=27730#p27730

I have also updated the Wiki.
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: problem querying pdf_temp

Unread post by steven »

Great, Thanks.


Steven
A short post is a good post.
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: problem querying pdf_temp

Unread post 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
A short post is a good post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: problem querying pdf_temp

Unread post 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;
 
    }
}
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: problem querying pdf_temp

Unread post by steven »

Thanks, that's what I needed.
A short post is a good post.
Post Reply