Jump to content

Getting first and last records, and total # of records


StardustSoul

Recommended Posts

Okay, So.

 

When we run variable jobs, we create an Variable Output sheet that has information for the copier operators. Right now, it is hand written by whomever composes the job and some people's handwriting leaves some copier operators to wonder if the forms were filled out by chickens.

 

It has to have the first and last number of records, and the first and last names of those records.

 

say the data has 602 records. (in this case the cellphone.txt from the tutorials)

I would need to populate n area on the form with 'record # 1' and another area with 'record # 602'

To coincide with that I need the '(Field)"Fname") + " " + (Field)"Lname")) for both first and last records.

So far I can populate the first record number and name with simple 'return' functions.

I have sussed out how to call in the last record number, using an OnRecordStart callback that I gleaned from surfing this forum. I have attached what I'm getting so far.

Only, to get that result, I am still getting composition of All records, (so a 602 page variable data sheet).

 

I've come this far in a week, teaching myself JavaScript in slow time at work and watching all the videos from PTI. Can someone help me figure out how to get this result by composing only one sheet?

 

(and if anyone wants to help fill in the other bits that are labeled according to what's needed that would be wonderful).

Thank you in advance.

~S

Variable Output Sheet (small).pdf

11111.zip

Link to comment
Share on other sites

I'm not sure I totally understand what you're trying to accomplish, nor exactly what your workflow is. Your text placeholders reference things like "name field from the first record of external data", but you're not actually using an external data file (XDF).

 

Anyway, I'm assuming that you are always going to reference all the records in the data file, i.e. the "From #" is always going to be 1. If that's the case, then you really do want to access the data file as an XDF in this job, so you only really need one main rule, OnRecordStart, to do something like this:

var data = new ExternalDataFileEx(FusionPro.inputFileName); // FusionPro.Composition.inputFileName for Server
FusionPro.Composition.AddVariable("Last Number", data.recordCount);
FusionPro.Composition.AddVariable("First Record Name", data.GetFieldValue(1, "FName") + " " + data.GetFieldValue(1, "LName"));
FusionPro.Composition.AddVariable("Last Record Name", data.GetFieldValue(data.recordCount, "FName") + " " + data.GetFieldValue(data.recordCount, "LName"));

You'll also want to set the start and end record numbers to 1 on the Input tab of the Composition Settings (or set these in OnJobStart if you prefer).

 

I've attached a modified version of your job with this change. I'm still not sure what the second table with CAN/(INT) is supposed to have in it that's different from the first US table, though.

 

Finally, if you want to compose this page along with the actual output records for the job, in a single composition, that's possible too, but the logic will be a bit different.

Variable Output Sheet (small)- Dan-1.pdf

Edited by Dan Korn
Link to comment
Share on other sites

First of all, thank you for helping me with this.

I was making it so much more difficult. Overthinking, that's my superpower.

 

You got what I was aiming for with the US part. The CAN/INT part would be the same, but with a different external data file. Is it possible to reference more than one external data file at a time?

 

We do mailings for local casinos, and since Canada has a different postal rate, they break our data into a US mailing and a Canada/international mailing.

Link to comment
Share on other sites

First of all, thank you for helping me with this.

I was making it so much more difficult. Overthinking, that's my superpower.

No problem. There are a lot of different ways to put a job together. It can be hard to know where to start.

You got what I was aiming for with the US part. The CAN/INT part would be the same, but with a different external data file. Is it possible to reference more than one external data file at a time?

Of course! Something like this:

var data_US = new ExternalDataFileEx(FusionPro.inputFileName); // FusionPro.Composition.inputFileName for Server
FusionPro.Composition.AddVariable("Last Number", data_US.recordCount);
FusionPro.Composition.AddVariable("First Record Name", data_US.GetFieldValue(1, "FName") + " " + data_US.GetFieldValue(1, "LName"));
FusionPro.Composition.AddVariable("Last Record Name", data_US.GetFieldValue(data_US.recordCount, "FName") + " " + data_US.GetFieldValue(data_US.recordCount, "LName"));

var data_CAN = new ExternalDataFileEx(FusionPro.inputFileName + "_CAN"); // or whatever the name of the CAN/INT data file is
FusionPro.Composition.AddVariable("Last Number CAN", data_CAN.recordCount);
FusionPro.Composition.AddVariable("First Record Name CAN", data_CAN.GetFieldValue(1, "FName") + " " + data_CAN.GetFieldValue(1, "LName"));
FusionPro.Composition.AddVariable("Last Record Name CAN", data_CAN.GetFieldValue(data_CAN.recordCount, "FName") + " " + data_CAN.GetFieldValue(data_CAN.recordCount, "LName"));

Though it's not clear to me how this works with multiple data files. I thought the whole idea is that you would have one of these "Variable Output sheets" generated to correspond to one output run of a job from one data file. Now it sounds like you want to have this Variable Output sheet job reference two different actual jobs, which I think could lead to confusion. More about this below...

We do mailings for local casinos, and since Canada has a different postal rate, they break our data into a US mailing and a Canada/international mailing.

Sure.

Oh, and no. This would be composed separately from the actual job. It doesn't really have anything to do with the actual composition.

Yeah, but it actually does. In fact, if you're going through the trouble to automate this, I think it would be advantageous to have this sheet as a cover sheet, included in the same output PDF (or PPML or whatever) file you're printing, so that you don't risk it being out of sync from the actual print job. But again, that would mean a one-to-one relationship of this cover sheet to a single print job output, which would preclude it working for two separate US and Canadian print jobs from two separate data files.

I just thought the Variable Output Sheet should be able to create itself instead of having to be filled out by hand.

Sure, any manual process you can automate is a good thing. (It's why you have a computer in the first place.)

 

Though as I noted above, since this job is referencing multiple "actual" data files, you probably want to pass the names of those data files to this "Variable Output sheet" or "cover" or "meta" job. I'm envisioning a "master" data file for this Variable Output Sheet job, which has just one record with two data fields in it, something like:

dataFile_US,dataFileCAN
cellphone.txt,cellphone_CAN.txt

Then the job will use that as its data file, and the rule will look up those data fields to get the names of the files to load up as XDFs, like so:

var data_US = new ExternalDataFileEx(Field("dataFile_US"));
FusionPro.Composition.AddVariable("Last Number", data_US.recordCount);
FusionPro.Composition.AddVariable("First Record Name", data_US.GetFieldValue(1, "FName") + " " + data_US.GetFieldValue(1, "LName"));
FusionPro.Composition.AddVariable("Last Record Name", data_US.GetFieldValue(data_US.recordCount, "FName") + " " + data_US.GetFieldValue(data_US.recordCount, "LName"));

var data_CAN = new ExternalDataFileEx(Field("dataFile_CAN"));
FusionPro.Composition.AddVariable("Last Number CAN", data_CAN.recordCount);
FusionPro.Composition.AddVariable("First Record Name CAN", data_CAN.GetFieldValue(1, "FName") + " " + data_CAN.GetFieldValue(1, "LName"));
FusionPro.Composition.AddVariable("Last Record Name CAN", data_CAN.GetFieldValue(data_CAN.recordCount, "FName") + " " + data_CAN.GetFieldValue(data_CAN.recordCount, "LName"));

Now you don't have to go change the data source for this Variable Output sheet job every time; you can just update that master data file to point to the two different actual data files.

 

Though again, I think it would be a better automation overall to include this sheet as part of the "actual" print job output, so that you don't have to do anything at all to sync up the names of the data files between this cover sheet job and the actual print job.

Link to comment
Share on other sites

It WORKS! Thank you!! :D

 

I finally followed the logic and instead of defining a specific data source at the beginning, I just defined it as 'none'. That make everything work.

 

Thank you again for helping me over this hurdle. You rock my hand knit socks!

 

What a great way to end a Friday! :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...