View Single Post
  #4  
Old January 29th, 2009, 05:32 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,592
Default Re: How to compose a range of records?

Quote:
Originally Posted by LeberMac View Post
I suppose I could write a giant if...then loop for every time I have to create a repairs file, but in reality it will be easier to just edit the .csv data file that gets imported. (And then compose JUST the records that need to be reprinted.)

So... hey - maybe Printable could put this feature request on the fast track for inclusion in 6.1?
Well, we'll certainly be glad to consider any new feature or enhancement requests, but I can't say what the priority of any given request will be. I'm not sure how many customers would make use of such a feature.

Quote:
Originally Posted by DSweet View Post
FusionPro.Composition.composeThisRecord = false;

If (CurrentRecordNumber() == 2) {
...FusionPro.Composition.composeThisRecord = true;
}
else if ((CurrentRecordNumber() >= 345) && (CurrentRecordNumber() <= 351)) {
...FusionPro.Composition.composeThisRecord = true;
}
else if ..... and so on

This way you only turn on the value to compose that specific record if it is within your range values in the if statements.
That will certainly work, but there are definitely more succinct ways to accomplish this kind of thing in JavaScript. First off, you can certainly replace all those multiple "if/else" blocks with a few uses of the || ("or") operator, like so:
Code:
FusionPro.Composition.composeThisRecord = (CurrentRecordNumber() == 2) ||
 ((CurrentRecordNumber() >= 345) && (CurrentRecordNumber() <= 351)) ||
 ((CurrentRecordNumber() >= 987) && (CurrentRecordNumber() <= 998));
return FusionPro.Composition.composeThisRecord;
But we can simplify this further by using a local variable, like so:
Code:
var val = CurrentRecordNumber();
FusionPro.Composition.composeThisRecord = (val == 2) ||
 ((val >= 345) && (val <= 351)) ||
 ((val >= 987) && (val <= 998));
return FusionPro.Composition.composeThisRecord;
HINT: Hitting Ctrl+F in the Rule Editor will bring up a Find/Replace dialog. Or, in FusionPro 6.0, there's a handy "Find..." button you can click.

Also, you can use the Building Blocks dialog to iterate through the records and test to make sure that the result is what you want for each record. That's why we're returning the value at the end. You could also use the Print statement to write a message to the log file for each record saying what the result is.

Still, this logic can be generalized even further. Consider this:
Code:
 
function CheckRanges(val)
{
  switch (val)
  {
    case 2:
    case 657:
    // etc.
      return true;
  }
 
  switch (true)
  {
    case (val >= 345 && val <= 351):
    case (val >= 987 && val <= 998):
    // etc.
      return true;
  }
 
  return false;
}
FusionPro.Composition.composeThisRecord = CheckRanges(CurrentRecordNumber());
return FusionPro.Composition.composeThisRecord;
You can see that adding more ranges is just a matter of adding "case" lines to the appropriate "switch" statement. (I didn't invent the "switch (true)" trick, but it's cool!)

But wait, there's more! If you order now, you also get this:
Code:
 
var ranges = [ 2, [345,351], 657, [987,998] ];
function CheckRanges(val)
{
  for (var i in ranges)
  {
    if (ranges[i] instanceof Array)
    {
      if (val >= ranges[i][0] && val <= ranges[i][1])
        return true;
    }
    else if (val == ranges[i])
      return true;
  }
 
  return false;
}
FusionPro.Composition.composeThisRecord = CheckRanges(CurrentRecordNumber());
return FusionPro.Composition.composeThisRecord;
It can cut open this tin can and still slice through a tomato!

Even more succinctly:
Code:
 
var ranges = [ 2, [345,351], 657, [987,998] ];
function CheckRanges(val)
{
  for (var i in ranges)
    if (val == ranges[i] || ((ranges[i] instanceof Array) && val >= ranges[i][0] && val <= ranges[i][1]))
      return true;
  return false;
}
FusionPro.Composition.composeThisRecord = CheckRanges(CurrentRecordNumber());
return FusionPro.Composition.composeThisRecord;
So, all you need to do to modify the ranges you want to recompose is to change this single line:
Code:
var ranges = [ 7, [15,34], [75,83] ]; //etc.
I can't imagine any enhancement to the GUI that would be any simpler than that.

This kind of thing is exactly why we provide a JavaScript-based rules subsystem with hooks into the composition engine, so that you can do whatever job-specific thing you want to do with a few lines of code, instead of us having to implement dozens of custom dialogs to do a small subset of what some customers might want.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote