Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Dates

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 19th, 2010, 09:54 PM
Mike Mike is offline
Junior Community Member
 
Join Date: Oct 2010
Posts: 10
Default Multi set body page usage based on dates

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",tru e);
else if (yearsBetween <= 40) FusionPro.Composition.SetBodyPageUsage("BackB",tru e);
else if (yearsBetween <= 60) FusionPro.Composition.SetBodyPageUsage("BackC",tru e);
else FusionPro.Composition.SetBodyPageUsage("BackD",tru e);

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",tru e) + FusionPro.Composition.SetBodyPageUsage("FrontA",tr ue);
else if (yearsBetween <= 40) FusionPro.Composition.SetBodyPageUsage("BackB",tru e) + FusionPro.Composition.SetBodyPageUsage("FrontB",tr ue);
;
else if (yearsBetween <= 60) FusionPro.Composition.SetBodyPageUsage("BackC",tru e)+ FusionPro.Composition.SetBodyPageUsage("FrontC",tr ue);
;
else FusionPro.Composition.SetBodyPageUsage("BackD",tru e) + FusionPro.Composition.SetBodyPageUsage("FrontD",tr ue);
;

Any help would be great.
Reply With Quote
  #2  
Old October 20th, 2010, 07:00 AM
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 869
Default Re: Multi set body page usage based on dates

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:
Code:
// 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).
Reply With Quote
  #3  
Old October 20th, 2010, 04:47 PM
Mike Mike is offline
Junior Community Member
 
Join Date: Oct 2010
Posts: 10
Default Re: Multi set body page usage based on dates

Thanks mate, your help is greatly appreciated.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:17 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.