Jump to content

How do I use a call back rule to create packing list?


Recommended Posts

I need to create a packing list.

- my list is of employees of a large company with their manager mailing address included.

-I want employees with matching manager addresses to be combined together onto a packing list. My "key" field should be driver for this.

 

I've read "how to return multiple records in the same output file" I get the gist of what it is doing.

 

I've searched the forums high and low and can't find a similar problem...but I'm sure I'm not the first.

 

I've attached a sample file and sample pdf.

 

Thanks!

samplesnippet.txt

MANIFEST.pdf

Link to comment
Share on other sites

I gave it a shot.. and I was able to get it to work. However I am having issues adding additional variables. For example I wanted to add a matching address for the "name" and and ID for the "account"

I am new to JavaScript.... so I am missing something obvious. I can get the new variables to show up in template but with ugly results.

Link to comment
Share on other sites

I gave it a shot.. and I was able to get it to work. However I am having issues adding additional variables. For example I wanted to add a matching address for the "name" and and ID for the "account"

I am new to JavaScript.... so I am missing something obvious. I can get the new variables to show up in template but with ugly results.

You should be able to follow the pattern set up for the other variables. But it's almost impossible to figure this out in the abstract. Can you collect up the job and post it here? I can't guarantee that I'll have the time to delve too deeply into custom template-building for you, but someone else might want to take a crack at it too.

Link to comment
Share on other sites

I guess I'm not bright enough...yet, to figure it out based on 2 variables. Hopefully with a couple more added I'll catch on.

Yeah, it's probably not quite as easy as I made it sound. Anyway, here's an updated OnRecordStart rule:

var XDF = new ExternalDataFileEx("sample.txt", "\t"); // <- YOUR DATA FILE NAME HERE
if (!XDF.valid)
  ReportError("Cannot successfully read/find the external data file.");

// Populate an array of record objects, each with a name and an array of accounts:
var Records = [];
var previousName = "";
for (var rec = 1; rec <= XDF.recordCount; rec++)
{
   var name = XDF.GetFieldValue(rec, "Name");
   if (name != previousName)
       Records.push({name:name, address1:XDF.GetFieldValue(rec, "Address1"), accounts:[]});

   Records[Records.length-1].accounts.push({name:XDF.GetFieldValue(rec, "Account"), id:XDF.GetFieldValue(rec, "employee_id")});
   previousName = name;
}

// Set repeat count:
FusionPro.Composition.repeatRecordCount = Records.length;

// Now set up variables for this record.

// Clear Account variables for a new repeat:
for (var i = 1; i <= XDF.recordCount; i++)
{
   FusionPro.Composition.AddVariable("Account" + i, "");
   FusionPro.Composition.AddVariable("EmployeeID" + i, "");
}

// Set up variables Name, Account1, Account2, etc., for use in text frames:
var ThisRecord = Records[FusionPro.Composition.repeatRecordNumber-1];
FusionPro.Composition.AddVariable("Name", ThisRecord.name);
FusionPro.Composition.AddVariable("Address1", ThisRecord.address1);
for (var i = 0; i < ThisRecord.accounts.length; i++)
{
   FusionPro.Composition.AddVariable("Account" + (i+1), ThisRecord.accounts[i].name);
   FusionPro.Composition.AddVariable("EmployeeID" + (i+1), ThisRecord.accounts[i].id);
}

// Globals to use in other rules instead of calling the Field function:
Name = ThisRecord.name;
Account = function(i) { return ThisRecord.accounts[i-1]; }
NumberOfAccounts = ThisRecord.accounts.length;

return Records.length;

Now you can use the variables EmployeeID1, EmployeeID2, etc., in your text frames, just like Account1, Account2, etc. (And of course the "accounts" here are actually order items, but I'll let you change those variable names if you want.) A more generalized solution is possible, to work with any data file with any number of fields; maybe I'll work on that.

 

Note that I just added a single "Address1" variable for each record, instead of "Address1_1", "Address1_2", etc., since it appears that each "ship to" name has only one unique address, even though each line in the data file repeats it. You could add some other logic to combine the name and address fields into a single "key" if you want. I suspect, though, that in a typical shipping scenario like this, the key field is probably a numeric order or customer ID, and there's a separate data file (or database table) used to look up the customer's name, address, etc by that ID number. So you could have yet another ExternalDataFileEx for that, which would be more like this example.

 

Also, a full-blown enterprise-level solution for something like this would probably use an actual relational database, with separate tables for order numbers, customers, and order items, and would do a data merge in custom code from the database to build a flat data file to send to FusionPro Server, instead of doing all of this at composition time in the JavaScript rules.

Link to comment
Share on other sites

  • 2 weeks later...

for some reason I missed your last post until now. Thanks!

If you guys are ever able to make a gui style rule builder for this type of thing I will be first inline to purchase the upgrade. More and more jobs I receive are requiring either comparison of fields within the data or of fields in two separate files.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...