Jump to content

Letter and Form- second page is static with varying page count of variable


Recommended Posts

I am sure this is possible using Java scripting but am unsure how to do this. I have attached the sample job, first page of the letter is Address etc... second page is a Form that can increase in page count depending on data. The second page of the form is a base or template with the data being the only change. I do not know how to call out FP to add more pages if necessary and what the data has to have added such as a special field for this to take place. The data is not combined currently into one csv but I can do that depending on what is needed for this to work.

Thanks,

TEST_Multipg.zip

Link to comment
Share on other sites

Hi,

 

I know Dan or Ste will have a much more elegant way of doing this but here’s my outline:

 

‘The data is not combined currently into one csv but I can do that depending on what is needed for this to work.’

 

Great! I’m assuming then the data is in some type of relational database, having a customer name and address table (or something similar) and a related details table. If this is the case, you’ll need to do the following. First, the data. Pick your favorite RDMS, I’ll use Access for this example. Add a new numeric field to the name and address table called detail_count. Write a select groupby query linking the N/A table to the detail table on the ID field and add a count(*) field. This will tell you how many detail records are associated to each N/A record. Next, write an update query linking the N/A table to this query by ID and update the N/A field detail_count with the queries count value.

 

Use FP manage pages feature to name each of the pages in the template and to set the initial use (On/Off). Call the first one something like COVER. Next, start adding the static variable data pages naming them PAGE1, PAGE2, PAGE3 etc till you’ve added the maximum number of child records possible setting the first to On and the rest to Off. You’ll also want to add a text box to each ‘static’ page. This text box will call a rule to populate the ‘static’ page with data from the global array.

 

You’ll obviously need an external data file for reading the detail records and a global array to hold the various detail info for each data field on each of the successive detail pages. You’ll also need a counter variable to know which ‘static’ page you’re currently processing.

 

In your OnRecordStart start rule, you’ll need to accomplish 2 things, 1st, a loop to turn on the required number of ‘static’ pages in the template that are needed (which you’ll know by the detail_count field). 2nd is to traverse the details table and load the global array with each of these ‘static’ pages variable data based on ID. You’ll also need to reset the global array counter here to zero.

 

The only thing left to do is write the PopulateStaticFields rule and include it on each ‘static’ page. This rule will add the appropriate data from the global array. Like I said, can it be accomplished… I think so, but this is only an outline from a tired old list programmers mind ;) On the other hand, I didn't see a barcode and it's ******* information, so I assume it's going out full first class. If you're doing 1000's or 10's of thousands of these, buy knowing the detail pages needed, you can calculate the weight of each recipients piece and pre-sort accordingly. Could be a significant postage savings.

 

I’ll be curious to see Dan’s or Step’s solution… there must be a more elegant way to do this!

 

Regards,

 

Gregg

Link to comment
Share on other sites

There are several ways that you can do this. Gregg has touched on how to accomplish this with static pages. You could even take that method a step further and only have two pages (a letter and a form) and repeat the record by the number of forms needed + 1 (for the letter) and then turn them on/off accordingly.

 

I don't think editing the data is necessary in your case, though, unless you just want to save yourself a line or two of code. You can tell how many forms you'll need by pulling your "form" data in as an external data file and counting the number of records that match your internal data record's key. I'm assuming that the "key" linking the two data files in your case is the "ID" field (i.e. if record 1 has an "ID" field value of "1", the template should create a form for every record with a "1" in the "ID" field of the external data file). Here's an example of how to determine the number of forms for a given record on-the-fly:

var data = new ExternalDataFileEx('./Test.Forms.csv', ',');
var forms = 0; // number of forms
for (var i=1; i<=data.recordCount; i++)
 if (data.GetFieldValue(i, 'ID') == Field("ID"))
   forms++;

 

Another way you could accomplish this is to use a Template page (or RepeatableComponent) and an overflow page. Here's how:

  1. FusionPro > Manage Pages > Page Usage...
  2. Select your second page and change the "type" to "Overflow" and name it "overflow"
  3. FusionPro > Manage Pages > Insert Page
  4. Type: "Template", Name: "Form", Duplicate Existing Page 2
  5. Draw a small text frame on the letter page (this will be used to overflow your forms)
  6. With the frame selected, click "Overflow..." in the frame properties window
  7. Select "Overflow text to new pages", New left page: "Overflow", Add pages: As few pages as possible
  8. Delete the FP frames from your overflow page (not the template page) and draw a large text frame that covers the page – it needs to be larger than the page itself.
  9. With the frame selected, click "Overflow to" in the properties window
  10. On the template page, you need to insert "fields" that you can populate from a rule. You can name them whatever you'd like but for the sake of example: open the text editor for the textbox beside "TIN:" and erase it's contents. In the "variable" field (don't select from the drop down list) type: "TIN" and press "insert". Your repeatable component now has a text variable named "TIN".
  11. Create a rule called "Form" containing the code below:
    //===================================================================================
    // Function to create a 'Form' Repeatable Component
    // Requires 1 argument 'obj' which should be an Object
    // For example: 
    //  - obj = {'key' : 'value'};
    //  - 'key' is the name of the variable on the Template Page 
    //  - 'value' is the value to display for that variable 
    //===================================================================================
     function Form(obj) {
       if (!arguments.length) // If not arguments are passed, return nothing
         return '';
       if (typeof obj != 'object') // If an object is not passed, throw an error
         ReportWarning('Expected an "object" but was passed a "' + typeof obj + '"');
    
       // Create Repeatable Component constructor (name should match template page)
       var form = new FPRepeatableComponent('Form');
    
       // Step through object values and assign them to their corresponding repeatable component variable 
       // Replace leading/trailing spaces and commas to handle empty fields formatting 
       for (var key in obj) 
         form.AddTextVar(key, Str(obj[key]).replace(/^[,\s]*|[,\s]*$/g,''));
    
       // Only return a form if at least one field is populated
       for (i in form.textVars)
         if (Str(form.textVars[i]))
           return form;
    
       // Otherwise, return an empty string.
       return '';
     }
    
    var result = []; // Array of forms
    var data = new ExternalDataFileEx('./Test.Forms.csv', ','); // External Data file
    
    // Throw error if we can't find the external Data
    if (!data.valid)
     ReportError('Unable to locate external data file');
    
    // Step through external data file and create forms for records that
    // match the 'ID' field of the current record.
    for (var i=1; i<=data.recordCount; i++) {
    
     // Just a function to make returning the value of the external data field a little cleaner
     function ExField(field) { return data.GetFieldValue(i, field) || ''; }
    
     // If the fields match, create the form
     if (ExField('ID') == Field("ID")) {
    
       // Object that maps Repeatable Component variables to their desired value
       var fields = {
         'TIN' : ExField('Provider TIN'),
         /* // Map the rest of the fields here
         'NAME' : NAME' : ExField('Practitioner First Name') + ' ' + ExField('Practitioner Last Name') + ', ' + ExField('Practitioner Degree'),
         'NPI' : ExField('Practitioner NPI'),
         */
       };
    
       // Create the form by calling the 'Form' function and add it to the array
       result.push(Form(fields));
     }
    }
    
    // Return the array of forms (repeatable components)
    return result.join('<p>');
    


  12. Insert that rule into the text box you created on the "letter" page.

 

I've attached an example template and proof of concept if you're interested. Please note that the attached is merely an example intended to demo my approach and since I am using an older version of FP than you are, the fields may differ (because I was just guessing when filling them in).

ste_Multipg.zip

proof.pdf

Edited by step
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...