Mike Posted October 20, 2010 Share Posted October 20, 2010 Eric has been kind enough to help me work out the following age based code and I have to say it works brilliantly to turn on and off the back pages only for printing. My question is how would I tell fusion to turn on and off both a front page and a back page. I am a noob and just can't get it to work. Below is the code that works perfect Code that works: // OnRecordStart Date.prototype.YearsBetween = function(){ var intMilYear = 365.23 * 24 * 60 * 60 * 1000; var intMilDif = arguments[0] - this; var intYears = Math.floor(intMilDif/intMilYear); return intYears; } var dob = new Date(Field("birthday")); // YOUR FIELD in a standard date format var today = new Date(); var yearsBetween = dob.YearsBetween(today); // Turn on age related backs for specific record (Pages named A,B,C,D and set to Unused) if (yearsBetween <=16) FusionPro.Composition.SetBodyPageUsage("BackA",true); else if (yearsBetween <= 40) FusionPro.Composition.SetBodyPageUsage("BackB",true); else if (yearsBetween <= 60) FusionPro.Composition.SetBodyPageUsage("BackC",true); else FusionPro.Composition.SetBodyPageUsage("BackD",true); What I need help with in red // OnRecordStart Date.prototype.YearsBetween = function(){ var intMilYear = 365.23 * 24 * 60 * 60 * 1000; var intMilDif = arguments[0] - this; var intYears = Math.floor(intMilDif/intMilYear); return intYears; } var dob = new Date(Field("birthday")); // YOUR FIELD in a standard date format var today = new Date(); var yearsBetween = dob.YearsBetween(today); // Turn on age related backs for specific record (Pages named A,B,C,D and set to Unused) if (yearsBetween <=16) FusionPro.Composition.SetBodyPageUsage("BackA",true) + FusionPro.Composition.SetBodyPageUsage("FrontA",true); else if (yearsBetween <= 40) FusionPro.Composition.SetBodyPageUsage("BackB",true) + FusionPro.Composition.SetBodyPageUsage("FrontB",true); ; else if (yearsBetween <= 60) FusionPro.Composition.SetBodyPageUsage("BackC",true)+ FusionPro.Composition.SetBodyPageUsage("FrontC",true); ; else FusionPro.Composition.SetBodyPageUsage("BackD",true) + FusionPro.Composition.SetBodyPageUsage("FrontD",true); ; Any help would be great. Link to comment Share on other sites More sharing options...
esmith Posted October 20, 2010 Share Posted October 20, 2010 My bad (sort of). I kept all the IF statements as one-liners since my example was only returning a single result per condition. In your case, you want to run 2+ commands so you need to place them on separate lines inside curly brackets "{}" as follows: // Turn on age related backs for specific record (Pages named A,B,C,D and set to Unused) if (yearsBetween <=16) { FusionPro.Composition.SetBodyPageUsage("BackA",true); FusionPro.Composition.SetBodyPageUsage("FrontA",true); } else if (yearsBetween <= 40) { FusionPro.Composition.SetBodyPageUsage("BackB",true); FusionPro.Composition.SetBodyPageUsage("FrontB",true); } else if (yearsBetween <= 60) { FusionPro.Composition.SetBodyPageUsage("BackC",true); FusionPro.Composition.SetBodyPageUsage("FrontC",true); } else { FusionPro.Composition.SetBodyPageUsage("BackD",true); FusionPro.Composition.SetBodyPageUsage("FrontD",true); } On another side note, if you enclose your JS code with the CODE tags, it will place your code in an interior gray box making it a little easier to separate code from general text in a forum post. The CODE tags are found in the WYSIWYG text editor denoted by the pound sign, or you can just surround your code with (code](/code] (replace left parenthesis with left square bracket). Link to comment Share on other sites More sharing options...
Mike Posted October 20, 2010 Author Share Posted October 20, 2010 Thanks mate, your help is greatly appreciated. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.