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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 3rd, 2009, 11:25 AM
Rayed Rayed is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 21
Default Need a little instructions on how to apply a rule

Hi,
I have a rule for a Disclaimer that I need to apply for an ongoing year so I don't have to re-upload the template everytime just to udate it. I got the rule from Printable, but I don't know where to place it in my current Disclaimer rule. Can you possibly help?

Here is my Disclaimer rule:

if (Field("CommunityNY") == "The Retreat at Carmel Condominiums")
return "The complete Offering Terms are in an Offering Plan available from the Sponsor CD06-0807. © 2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";


else if (Field("CommunityNY") == "Brighton Green")
return "The complete Offering Terms are in an Offering Plan available from the Sponsor CD05-0473. ©2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";

else if (Field("CommunityNY") == "Water's Edge at Point Pleasant")
return "©2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";

else if (Field("CommunityNY") == "River Pointe by Del Webb")
return "Age-restricted community; occupancy restrictions apply. Occupants must include at least one resident 55 years of age or better, some residents may be younger and no one under 19 in permanent residence. Additional restrictions may apply. Community association fees and additionial fees may be required. ©2009, Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";

else if (Field("CommunityNY") == "Wanaque Reserve by Del Webb")
return "Age-restricted community; occupancy restrictions apply. Occupants must include at least one resident 55 years of age or better, some residents may be younger and no one under 19 in permanent residence. Additional restrictions may apply. Community association fees and additionial fees may be required. ©2009, Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";

else if (Field("CommunityNY") == "Keystone Estates")
return "©2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";

else return "©2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";

NOW HERE IS THE NEW RULE I WOULD INSERT:

return FormatDate(Today(), "yyyy");

Where does that new rule go, in the year area?
Thanks,
Rayed
Reply With Quote
  #2  
Old February 4th, 2009, 07:45 AM
DSweet's Avatar
DSweet DSweet is offline
Senior Contributor
 
Join Date: Sep 2008
Location: Oberlin, Ohio
Posts: 248
Default Re: Need a little instructions on how to apply a rule

Rayed,

Where did you want the date to appear in the disclaimer? In front of your text or after it?

You may want to change your rule slightly to make it simpler. Within each if-else statement instead of "return", just set a text string to be equal to the string that you want to return....
Code:
var outString2 = "";
 
if (Field("CommunityNY") == "The Retreat at Carmel Condominiums")
outString2 = "The complete Offering Terms are in an Offering Plan available from the Sponsor CD06-0807. © 2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";
 
else if (Field("CommunityNY") == "Brighton Green")
outString2 = "The complete Offering Terms are in an Offering Plan available from the Sponsor CD05-0473. ©2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";
 
else if (Field("CommunityNY") == "Water's Edge at Point Pleasant")
outString2 = "©2009 Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";
 
and so on....
Then in your final return statement at the end of your rule you simply put for a date first placement...
return FormatDate(Today(), "yyyy") + ", " + outString2

or for a date last statement...

return outString2 + ", " + FormatDate(Today(), "yyyy");




Another few tips to look into trying. Since you state that you don't want to have to re-load the template each time for a different year, go one step further and reprogram the template so you don't have to reload it if a disclaimer changes. If you make each discalimer a resource as a tagged-text file, then all you'll need to do to change a disclaimer is to update that tagged-text file and not the template itself. This way your coding will be even cleaner and look something like...
Code:
var outString2 = "";
 
if (Field("CommunityNY") == "The Retreat at Carmel Condominiums")
outString2 = Resource("DisclaimerRCC");
 
else if (Field("CommunityNY") == "Brighton Green")
outString2 = Resource("DisclaimerBG");
 
else if (Field("CommunityNY") == "Water's Edge at Point Pleasant")
outString2 = Resource("DisclaimerWEPP");
 
else if (Field("CommunityNY") == "River Pointe by Del Webb")
outString2 = Resource("DisclaimerRPDW");
 
else if (Field("CommunityNY") == "Wanaque Reserve by Del Webb")
outString2 = Resource("DisclaimerWRDW");
 
else if (Field("CommunityNY") == "Keystone Estates")
outString2 = Resource("DisclaimerKE");
 
else outString2 = Resource("DisclaimerDefault");
 
return outString2 + ", " + FormatDate(Today(), "yyyy");
or even simpler as a switch rule...

Code:
switch (Field("CommunityNY"))
{
 case "The Retreat at Carmel Condominiums" : outString2 = Resource("DisclaimerRCC");
 case "Brighton Green" : outString2 = Resource("DisclaimerBG");
 case "Water's Edge at Point Pleasant" : outString2 = Resource("DisclaimerWEPP");
 case "River Pointe by Del Webb" : outString2 = Resource("DisclaimerRPDW");
 case "Wanaque Reserve by Del Webb" : outString2 = Resource("DisclaimerWRDW");
 case "Keystone Estates" : outString2 = Resource("DisclaimerKE");
 default : outString2 = Resource("DisclaimerDefault");
}
 
return outString2 + ", " + FormatDate(Today(), "yyyy");
Good Luck
__________________
David A. Sweet
Variable Data Specialist
HKM Direct Market Communications
Windows 7, Acrobat 10.x
FusionPro Desktop and Server 10.0.26
Reply With Quote
  #3  
Old February 4th, 2009, 10:39 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,502
Default Re: Need a little instructions on how to apply a rule

A couple of comments. First, if you already have the rule set up and it's doing everything you want except that you want the year to always be the current year, then all you need to do is have another rule call the first one and replace the year, like so:
Code:
return ReplaceSubstring(Rule("OriginalRuleName"), "2009", FormatDate(Today(), "yyyy"));
Again, if you do this then you don't need to modify your original rule at all.

Also, all of David's suggestions are excellent, and a switch statement is a great way to simplify a bunch of consecutive "if/else" statements, but I have to nitpick a bit with this logic:
Quote:
Originally Posted by DSweet View Post
or even simpler as a switch rule...
Code:
switch (Field("CommunityNY"))
{
case "The Retreat at Carmel Condominiums" : outString2 = Resource("DisclaimerRCC");
case "Brighton Green" : outString2 = Resource("DisclaimerBG");
case "Water's Edge at Point Pleasant" : outString2 = Resource("DisclaimerWEPP");
case "River Pointe by Del Webb" : outString2 = Resource("DisclaimerRPDW");
case "Wanaque Reserve by Del Webb" : outString2 = Resource("DisclaimerWRDW");
case "Keystone Estates" : outString2 = Resource("DisclaimerKE");
default : outString2 = Resource("DisclaimerDefault");
}
 
return outString2 + ", " + FormatDate(Today(), "yyyy");
First of all, this logic doesn't exactly do what the original poster wants, unless the date always comes at the end. Second, if you actually try this, you'll see that the value is always set to Resource("DisclaimerDefault"), no matter what the Field("CommunityNY") value is. The reason is that you need to use "break" statements in a switch statement like this to avoid this problem:
https://developer.mozilla.org/en/Cor...tements/switch

See the break; statements I've added below in red:
Code:
switch (Field("CommunityNY"))
{
case "The Retreat at Carmel Condominiums" : outString2 = Resource("DisclaimerRCC"); break;
case "Brighton Green" : outString2 = Resource("DisclaimerBG"); break;
case "Water's Edge at Point Pleasant" : outString2 = Resource("DisclaimerWEPP"); break;
case "River Pointe by Del Webb" : outString2 = Resource("DisclaimerRPDW"); break;
case "Wanaque Reserve by Del Webb" : outString2 = Resource("DisclaimerWRDW"); break;
case "Keystone Estates" : outString2 = Resource("DisclaimerKE"); break;
default : outString2 = Resource("DisclaimerDefault"); break;
}
 
return outString2 + ", " + FormatDate(Today(), "yyyy");
Although another way to avoid this is to simply create a function and return the values from the switch statement directly, like so:
Code:
function GetDisclaimer()
{
  switch (Field("CommunityNY"))
  {
    case "The Retreat at Carmel Condominiums" : return Resource("DisclaimerRCC");
    case "Brighton Green" : return Resource("DisclaimerBG");
    case "Water's Edge at Point Pleasant" : return Resource("DisclaimerWEPP");
    case "River Pointe by Del Webb" : return Resource("DisclaimerRPDW");
    case "Wanaque Reserve by Del Webb" : return Resource("DisclaimerWRDW");
    case "Keystone Estates" : return Resource("DisclaimerKE");
    default : return Resource("DisclaimerDefault");
}
 
return GetDisclaimer() + ", " + FormatDate(Today(), "yyyy");
Of course, you could also use the Switch Wizard to create a rule which does exactly what this function does, that is, map a field value to a resource. (From the menu, FusionPro -> Edit Rules, click "New", click "Next", then select the "CommunityNY" field and change the Return Type to "Text Resource", give the rule a name such as "Disclaimer", click "Next", and assign the resources to the field values.) Then you can simply use the result of the Switch Wizard rule in your JavaScript rule, like so:
Code:
return Rule("Disclaimer") + ", " + FormatDate(Today(), "yyyy");
Or, getting back to the original question, you can always convert the original rule to use Formatted Text resources, but in the spirit of the original poster's question, he still probably wants to do this with the result:
Code:
return ReplaceSubstring(Rule("OriginalRuleName"), "2009", FormatDate(Today(), "yyyy"));
__________________
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
  #4  
Old February 4th, 2009, 10:57 AM
Rayed Rayed is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 21
Default Re: Need a little instructions on how to apply a rule

Wow David,
Thanks for all of the rule info. I think I will try the Resource Tagged Text file rule.
So basically, I would paste the community rule information in a text file and save that file with the name "DisclaimerRCC" for example.
Then I would upload that text file as a resource in my template. Then when I need to change that date all I have to do is update it and re-upload that text file to the Manager?
That sounds simple enough. I will let you know how it goes.
Thanks,
Rayed
Reply With Quote
  #5  
Old February 4th, 2009, 11:33 AM
Rayed Rayed is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 21
Default Re: Need a little instructions on how to apply a rule

Dan,
Thanks for the added clarification. I will need some time to figure out all of those rules. I like your idea however of the second rule to call the first one.
Rayed
Reply With Quote
  #6  
Old February 4th, 2009, 11:53 AM
Rayed Rayed is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 21
Default Re: Need a little instructions on how to apply a rule

Dan,
I applied your rule in a rule and it seemed to work. I can see the disclaimer and year for each community, I just wish there was a way to check if it will change each year.
I will now begin re-uploading and copying 33 templates with the new rule.
Thanks,
Rayed
Reply With Quote
  #7  
Old February 4th, 2009, 01:06 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,502
Default Re: Need a little instructions on how to apply a rule

Quote:
Originally Posted by Rayed View Post
I applied your rule in a rule and it seemed to work. I can see the disclaimer and year for each community, I just wish there was a way to check if it will change each year.
Well, other than waiting until next year, there really isn't a way to see what a statement such as FormatDate(Today(), "yyyy")) will do. You can always change the rule to something like this temporarily:
Code:
 return ReplaceSubstring(Rule("OriginalRuleName"), "2009", "THIS IS WHERE THE YEAR GOES");
You could also try other dates and see what happens, like so:
Code:
 return ReplaceSubstring(Rule("OriginalRuleName"), "2009", FormatDate(DateFromString("1/1/2003"), "yyyy")));
Other than that, you'll just have to take my word for it that the Today() function will always return an object representing the current date.

Keep in mind also that this will only reflect the date when the job is composed. I'm not sure what your fulfillment requirements are, but it seems likely that you might get to the point, say, in December, when you're preparing a job intended for publishing or mailing in the following year. So "Today" may not be what you want at all, in which case you might be better off just hard-coding a specific year into the rule:
Code:
return ReplaceSubstring(Rule("OriginalRuleName"), "2009", "2010");
Or, make another rule or a global variable which all the other rules can reference:
Code:
// This rule is named "CopyrightYear"
return "2010";
and:
Code:
return ReplaceSubstring(Rule("OriginalRuleName"), "2009", Rule("CopyrightYear"));
Quote:
Originally Posted by Rayed View Post
I will now begin re-uploading and copying 33 templates with the new rule.
Well, not to confuse things further, but if you're going to go to all this trouble to refactor your rules and resources, I would just use the rule returning the appropriate year wherever it's needed in the first place, instead of doing a programmatic replacement. So if you first set up a rule called something like "CopyrightYear" as above, then when you're entering the text of each Formatted Text Resource in the Variable Text Editor, you can just insert the "CopyrightYear" variable in place of the hard-coded year number. Or, if you want to keep all the text in JavaScript, you can do something like this:
Code:
return "©" + Rule("CopyrightYear") + " Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";
Alternatively:
Code:
return "&copy;<variable name=CopyrightYear>&#32;Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";
This approach, whether you call out the variable in the Variable Text Editor or in JavaScript code, makes it a lot more explicit when you look at the code or the resource that the value you're going to end up with in the output is defined elsewhere, instead of having to remember that some other code somewhere else is modifying what you're looking at.

This more direct approach also avoids an unlikely, but not zero, possibility that you'll accidentally replace more than what you intended, such as if a value of "2009" which doesn't represent the year, say as just a dollar amount in a table, happens to occur in the string you're modifying. Or if your job is modified to include some other kind of date, such as the sign-up year, which you don't want to automatically change to the current year. The last thing you want is to be changing numbers unintentionally. Maybe your current job isn't doing that now, but you never know what else is going to be built upon it in the future.
__________________
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
  #8  
Old February 4th, 2009, 02:43 PM
Rayed Rayed is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 21
Default Re: Need a little instructions on how to apply a rule

Dan,
Yes, I think you do have a point regarding the year possibly being confused with other numbers in the disclaimer. So I think I will go for the "CopyrightYear" rule. I will try it out and see if I can get it to work. Thanks a lot for your in-depth information and help.
Rayed
Reply With Quote
  #9  
Old February 9th, 2009, 10:45 AM
Rayed Rayed is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 21
Default Re: Need a little instructions on how to apply a rule

Dan and David,

Here is the Rule that I am applying to the Disclaimer on my templates. I thought I would pass it through you to see if it is okay. I did have to change the year to 2009 in my other rule "rule_communityNYDisclaimer" in order for it to work. So I am crossing my fingers that it will auto update to 2010 by next year. If I did something incorrectly, please let me know ASAP since I am in the process of updating all 33 templates.
Thanks,
Rayed


rule_CopyrightYear

return FormatDate(Today(), "yyyy");


rule_DisclaimerOnGoingYear (I placed this rule in my disclaimer box.)

return ReplaceSubstring(Rule("rule_communityNYDisclaimer" ), "2009", Rule("rule_CopyrightYear"));
Reply With Quote
  #10  
Old February 9th, 2009, 11:08 AM
LeberMac's Avatar
LeberMac LeberMac is offline
Junior Community Member
 
Join Date: Jan 2009
Location: Milwaukee, WI
Posts: 25
Default Re: Need a little instructions on how to apply a rule

For testing: can't you just change the date in the Date & Time System Prefs (on OS X) or in the Date & Time control panel (On Windows) ?

(Just remember to change it back after testing...)
__________________
"I say we take off and nuke the entire site from orbit. It's the only way to be sure."
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:44 AM.


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