MarcomCentral (PTI) and FusionPro User Communities

MarcomCentral (PTI) and FusionPro User Communities (http://forums.pti.com/index.php)
-   The JavaScript Library (http://forums.pti.com/forumdisplay.php?f=23)
-   -   All records not outputting ? (http://forums.pti.com/showthread.php?t=5247)

ThePorge October 31st, 2018 06:59 AM

All records not outputting ?
 
I've got a test data file containing 7 records. When I compose the file I only get one record output. "All" is selected in the compose window. The following text is from the message log (Minus the header info):
Composing record #1, input record 1
Composing record #2, input record 2
Composing record #3, input record 3
Composing record #4, input record 4
Composing record #5, input record 5
Composing record #6, input record 6
Composing record #7, input record 7
Job ended 09:32:19 - 1540992739.
Total Job Time: 1s

I'm not getting any other errors.

fyi. This file uses JavaScript code in the OnRecordStart callback to set the Page outputs and some address fields that may or may not contain an address. On my machine this file also exhibits the Preview jpg not showing, but being correct on output.

Mac 10.13.6
FusionPro® VDP Creator 10.0.26
Acrobat Build: 19.8.20080.306727
:confused:

ScottHillock October 31st, 2018 11:27 AM

Re: All records not outputting ?
 
Can you post the files? It's probably some error in your OnRecordStart.

ThePorge October 31st, 2018 11:47 AM

Re: All records not outputting ?
 
Sorry for getting this in the JavaScript thread.

Anyway...I know I didn't do this, but all the page usage was was set to "Unused" in the Manage page area...Or maybe I'm just going nuts?

Still have no images on the preview.

ThePorge October 31st, 2018 12:16 PM

Re: All records not outputting ?
 
Nope, that's not it either. All that does is have all pages output. Not what I'm looking for either. Scott can I send you this personally? I'd have to strip out Customer data before I'd want to post to a public forum.

ThePorge October 31st, 2018 12:30 PM

Re: All records not outputting ?
 
Here is everything I currently have in the OnRecordStart
**Note. I'm seeing some weird spaces in my code previewing on the web page that don't exist

Quote:

//Look to the Javascript Globals settings for the declared variables.

function myReturn(a){
if(a !=""){
a = "\n" + a;
}
return a;
}
function myPh(a){
if(a !=""){
a = "\nP: " + a;
}
return a;
}
function myFax(a){
if(a !=""){
a = "\nF: " + a;
}
return a;
}

if (Field("Pharmacy1")){
pharms.push(Field("Pharmacy1"));
pharmAdd.push(Field("Street1") +myReturn(Field("Suite1")) +"\n"+ Field("City1") +", "+Field("State1") +" "+Field("Zip1") + myPh(Field("Phone1")) + myFax(Field("Fax1")));
}

if (Field("Pharmacy2")){
pharms.push(Field("Pharmacy2"));
pharmAdd.push(Field("Street2") +myReturn(Field("Suite2")) +"\n"+ Field("City2") +", "+Field("State2") +" "+Field("Zip2") + myPh(Field("Phone2")) + myFax(Field("Fax2")));
}

if (Field("Pharmacy3")){
pharms.push(Field("Pharmacy3"));
pharmAdd.push(Field("Street3") +myReturn(Field("Suite3")) +"\n"+ Field("City3") +", "+Field("State3") +" "+Field("Zip3") + myPh(Field("Phone3")) + myFax(Field("Fax3")));
}
//Allows the skipping of data rows that don't contain a Pharmacy and shifts the data forward. eg. All data in group 3 goes to 2 if 2 is empty.
if (pharms[0]){
address1=pharmAdd[0];
pharmacy1 = pharms[0];
}
if (pharms[1]){
address2=pharmAdd[1];
pharmacy2 = pharms[1];
}
if (pharms[2]){
address3=pharmAdd[2];
pharmacy3 = pharms[2];
}

if (pharms.lenght == 1){
FusionPro.Composition.SetBodyPageUsage("One",true) ;
FusionPro.Composition.SetBodyPageUsage("Two",true) ;
FusionPro.Composition.SetBodyPageUsage("Three",fal se);
FusionPro.Composition.SetBodyPageUsage("Four",fals e);
FusionPro.Composition.SetBodyPageUsage("Five",fals e);
FusionPro.Composition.SetBodyPageUsage("Six",false );
}

if (pharms.lenght == 2){
FusionPro.Composition.SetBodyPageUsage("One",false );
FusionPro.Composition.SetBodyPageUsage("Two",false );
FusionPro.Composition.SetBodyPageUsage("Three",tru e);
FusionPro.Composition.SetBodyPageUsage("Four",true );
FusionPro.Composition.SetBodyPageUsage("Five",fals e);
FusionPro.Composition.SetBodyPageUsage("Six",false );
}

if (pharms.lenght == 3){
FusionPro.Composition.SetBodyPageUsage("One",false );
FusionPro.Composition.SetBodyPageUsage("Two",false );
FusionPro.Composition.SetBodyPageUsage("Three",fal se);
FusionPro.Composition.SetBodyPageUsage("Four",fals e);
FusionPro.Composition.SetBodyPageUsage("Five",true );
FusionPro.Composition.SetBodyPageUsage("Six",true) ;
}
/*switch(pharms.length){

case 1: FusionPro.Composition.SetBodyPageUsage("One",true) ;
FusionPro.Composition.SetBodyPageUsage("Two",true) ;
break;
case 2: FusionPro.Composition.SetBodyPageUsage("Three",tru e);
FusionPro.Composition.SetBodyPageUsage("Four",true );
break;
case 3: FusionPro.Composition.SetBodyPageUsage("Five",true );
FusionPro.Composition.SetBodyPageUsage("Six",true) ;
}*/

Dan Korn November 1st, 2018 10:26 AM

Re: All records not outputting ?
 
Thanks, posting the code is helpful. It's still hard to completely analyze this by looking through the keyhole of just the JavaScript rule, without having the rest of the job.

That said, I think the root of your problem is this:
Code:

if (pharms.lenght == 1){
You've misspelled the Array "length" property. Changing all those to this will probably help:
Code:

if (pharms.length == 1){
Also, your code with all those FusionPro.Composition.SetBodyPageUsage calls is way more verbose than it needs to be. Your commented-out switch statement is much better. But if you set all those pages to be Unused in the Page Usage dialog (and you don't even need to name them), then I think you can replace it all with this:
Code:

var frontPage = ((pharms.length - 1) * 2) + 1;
FusionPro.Composition.SetBodyPageUsage(frontPage, true );
FusionPro.Composition.SetBodyPageUsage(++frontPage, true);

And anyone who's been on this forum for a while probably won't be surprised when I tell you that the other code, with the three blocks for Pharmacy1, Pharmacy2, and Pharmacy3, can also be reduced with a "for" loop, like so:
Code:

for (var i = 1; i <= 3; i++)
{
    if (Field("Pharmacy" + i)){
        pharms.push(Field("Pharmacy" + i));
        pharmAdd.push(Field("Street" + i) +myReturn(Field("Suite" + i)) +"\n"+ Field("City" + i) +", "+Field("State" + i) +" "+Field("Zip" + i) + myPh(Field("Phone" + i)) + myFax(Field("Fax" + i)));
    }
}

Other code reductions are possible as well.

ThePorge November 1st, 2018 12:54 PM

Re: All records not outputting ?
 
I took out the page names and changed my code per your suggestions to
Quote:

//Look to the Javascript Globals settings for the declared variables. var pharmAdd=[], pharms = [], address1, address2, address3, pharmacy1, pharmacy2, pharmacy3;

function myReturn(a){
if(a !=""){
a = "\n" + a;
}
return a;
}
function myPh(a){
if(a !=""){
a = "\nP: " + a;
}
return a;
}
function myFax(a){
if(a !=""){
a = "\nF: " + a;
}
return a;
}


//Assign Pharmacy Names to pharms array and corresponding address to pharmAdd array.
//Allows the skipping of data rows that don't contain a Pharmacy and shifts the data forward. eg. All data in group 3 goes to array 2 if group 2 is empty.
for (var i = 1; i <= 3; i++)
{
if (Field("Pharmacy" + i)){
pharms.push(Field("Pharmacy" + i));
pharmAdd.push(Field("Street" + i) +myReturn(Field("Suite" + i)) +"\n"+ Field("City" + i) +", "+Field("State" + i) +" "+Field("Zip" + i) + myPh(Field("Phone" + i)) + myFax(Field("Fax" + i)));
}
}

if (pharms[0]){
address1=pharmAdd[0];
pharmacy1 = pharms[0];
}
if (pharms[1]){
address2=pharmAdd[1];
pharmacy2 = pharms[1];
}
if (pharms[2]){
address3=pharmAdd[2];
pharmacy3 = pharms[2];
}

var frontPage = ((pharms.length - 1) * 2) + 1;
FusionPro.Composition.SetBodyPageUsage(frontPage, true );
FusionPro.Composition.SetBodyPageUsage(++frontPage , true);
However when I compose it I get the following which again has me baffled??
Quote:

Composing record #1, input record 1
uncaught exception: Error: In SetBodyPageUsage(), invalid page number 9
Composing record #2, input record 2
uncaught exception: Error: In SetBodyPageUsage(), invalid page number 11
Composing record #3, input record 3
uncaught exception: Error: In SetBodyPageUsage(), invalid page number 15
Composing record #4, input record 4
uncaught exception: Error: In SetBodyPageUsage(), invalid page number 19
Composing record #5, input record 5
uncaught exception: Error: In SetBodyPageUsage(), invalid page number 25
Composing record #6, input record 6
uncaught exception: Error: In SetBodyPageUsage(), invalid page number 29
Composing record #7, input record 7
uncaught exception: Error: In SetBodyPageUsage(), invalid page number 31
Composing record #8, input record 8
Job ended 15:40:16 - 1541101216.
Total Job Time:
...and good Lord I looked and that code for two days and didn't see I miss-spelled length...AAAAhHHHHHHHH!!!!!

ThePorge November 1st, 2018 12:55 PM

Re: All records not outputting ?
 
Ohh, I have also run the update to FP 10.1.9

Dan Korn November 1st, 2018 01:01 PM

Re: All records not outputting ?
 
Quote:

Originally Posted by ThePorge (Post 21569)
However when I compose it I get the following which again has me baffled??

So again, without the job files, I kind of have to guess as to the larger context of what's going on. But the pharms array is global, and this code is in OnRecordStart, right? So I think you need to clear your arrays for each record, like so, at the start of the rule:
Code:

pharms = [];
pharmAdd = [];

Quote:

Originally Posted by ThePorge (Post 21569)
...and good Lord I looked and that code for two days and didn't see I miss-spelled length...AAAAhHHHHHHHH!!!!!

Sometimes when you're stuck like this, it's good to add some debugging code, just to "sanity check" your logic. Adding a line such as:
Code:

return pharms.lenght;
would probably have led you to find the mistake. And even adding
Code:

return pharms.length;
would have helped to figure out why you were getting those invalid page numbers, because your global array wasn't being cleared between records. I often leave little debugging lines like that in the rule, commented out.

ThePorge November 1st, 2018 01:25 PM

Re: All records not outputting ?
 
Dan, you were spot on with clearing the array. Thank you so much this is now working fantastic!!!


All times are GMT -7. The time now is 11:48 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.