Jump to content

Need a little instructions on how to apply a rule


Rayed

Recommended Posts

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

Link to comment
Share on other sites

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....

[color=black]var outString2 = "";[/color]

[color=black]if (Field("CommunityNY") == "The Retreat at Carmel Condominiums")[/color]
[color=black]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.";[/color]

[color=black]else if (Field("CommunityNY") == "Brighton Green")[/color]
[color=black]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.";[/color]

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

[color=black]and so on....[/color]

 

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...

[color=black]var outString2 = "";[/color]

[color=black]if (Field("CommunityNY") == "The Retreat at Carmel Condominiums")[/color]
[color=black]outString2 = Resource("DisclaimerRCC");[/color]

[color=black]else if (Field("CommunityNY") == "Brighton Green")[/color]
[color=black]outString2 = Resource("DisclaimerBG");[/color]

[color=black]else if (Field("CommunityNY") == "Water's Edge at Point Pleasant")[/color]
[color=black]outString2 = Resource("DisclaimerWEPP");[/color]

[color=black]else if (Field("CommunityNY") == "River Pointe by Del Webb")[/color]
[color=black]outString2 = Resource("DisclaimerRPDW");[/color]

[color=black]else if (Field("CommunityNY") == "Wanaque Reserve by Del Webb")[/color]
[color=black]outString2 = Resource("DisclaimerWRDW");[/color]

[color=black]else if (Field("CommunityNY") == "Keystone Estates")[/color]
[color=black]outString2 = Resource("DisclaimerKE");[/color]

[color=black]else outString2 = Resource("DisclaimerDefault");[/color]

[color=black]return outString2 + ", " + FormatDate(Today(), "yyyy");[/color]

 

or even simpler as a switch rule...

 

[color=black]switch (Field("CommunityNY"))[/color]
[color=black]{[/color]
[color=black] case "The Retreat at Carmel Condominiums" : outString2 = Resource("DisclaimerRCC");[/color]
[color=black] case "Brighton Green" : outString2 = Resource("DisclaimerBG");[/color]
[color=black] case "Water's Edge at Point Pleasant" : outString2 = Resource("DisclaimerWEPP");[/color]
[color=black] case "River Pointe by Del Webb" : outString2 = Resource("DisclaimerRPDW");[/color]
[color=#000000] case "Wanaque Reserve by Del Webb" : outString2 = Resource("DisclaimerWRDW");[/color]
[color=#000000] case "Keystone Estates" : outString2 = Resource("DisclaimerKE");[/color]
[color=#000000] default : outString2 = Resource("DisclaimerDefault");[/color]
[color=#000000]}[/color]

[color=#000000]return outString2 + ", " + FormatDate(Today(), "yyyy");[/color]

 

Good Luck

Link to comment
Share on other sites

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:

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:

or even simpler as a switch rule...

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/Core_JavaScript_1.5_Reference/Statements/switch

 

See the break; statements I've added below in red:

switch (Field("CommunityNY"))
{
case "The Retreat at Carmel Condominiums" : outString2 = Resource("DisclaimerRCC"); [color=#ff0000]break;[/color]
case "Brighton Green" : outString2 = Resource("DisclaimerBG"); [color=#ff0000]break;[/color]
case "Water's Edge at Point Pleasant" : outString2 = Resource("DisclaimerWEPP"); [color=#ff0000]break;[/color]
case "River Pointe by Del Webb" : outString2 = Resource("DisclaimerRPDW"); [color=#ff0000]break;[/color]
case "Wanaque Reserve by Del Webb" : outString2 = Resource("DisclaimerWRDW"); [color=#ff0000]break;[/color]
case "Keystone Estates" : outString2 = Resource("DisclaimerKE"); [color=#ff0000]break;[/color]
default : outString2 = Resource("DisclaimerDefault"); [color=red]break;[/color]
}

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:

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:

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:

return ReplaceSubstring(Rule("OriginalRuleName"), "2009", FormatDate(Today(), "yyyy"));

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

 return ReplaceSubstring(Rule("OriginalRuleName"), "2009", "THIS IS WHERE THE YEAR GOES");

You could also try other dates and see what happens, like so:

 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:

return ReplaceSubstring(Rule("OriginalRuleName"), "2009", "2010");

Or, make another rule or a global variable which all the other rules can reference:

// This rule is named "CopyrightYear"
return "2010";

and:

return ReplaceSubstring(Rule("OriginalRuleName"), "2009", Rule("CopyrightYear"));

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:

return "©" + Rule("CopyrightYear") + "&[font=Tahoma]#[/font]32;Pulte Homes, Inc. Void where prohibited. Subject to changes, errors and omissions without notice.";

Alternatively:

return "©<variable name=CopyrightYear>&[font=Tahoma]#[/font]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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"));

Link to comment
Share on other sites

Well, I changed the Date/Time on my Mac to 2010, but the online pdf proof Disclaimer still said 2009.

 

So now I am wondering, is the pdf proof and hi-res proofs generated online use an internal Printable Date and Time that the rule:

"return FormatDate(Today(), "yyyy");" could be picking up?

 

Or does that rule pick up the date and time from what ever computer initiates the download?

 

I just think that my rule is not correct and is not applying the year correctly.

Rayed

Link to comment
Share on other sites

Hrm. I dunno. I defer to Sweet and Dan on this one.

I'm unsure as to where FusionPro picks up its date & time data.

 

Stupid question that I forgot to ask - you are using FusionPro Desktop, right? (Cause if it's being composed somewhere else, you'll need to change the date/time there. Forgive me if that seems like the condescending "Is your computer plugged in?" tech support question.)

Link to comment
Share on other sites

Yes, I am using FusionPro Desktop on my Mac which is plugged in. But I think it is my rule. I don't think I did it right.

Thanks for your suggestions, however.

 

I suppose if Dan or David took a look at my rule, they could tell me if I applied it correctly.

One question I had for Dan, which could be obvious is, what exact rule information goes into the "rule_Copyright" rule. I assumed it was this:

"return FormatDate(Today(), "yyyy");" but he did not specify.

Thanks,

Rayed

Link to comment
Share on other sites

Well, I changed the Date/Time on my Mac to 2010, but the online pdf proof Disclaimer still said 2009.

 

So now I am wondering, is the pdf proof and hi-res proofs generated online use an internal Printable Date and Time that the rule:

"return FormatDate(Today(), "yyyy");" could be picking up?

 

Or does that rule pick up the date and time from what ever computer initiates the download?

 

I just think that my rule is not correct and is not applying the year correctly.

Rayed

The Today() function returns a JavaScript Date object representing the current system date and time, on the machine where the function is called. At composition time, it returns the system date and time on the machine where the composition is performed. So, if you're composing on a remote FP Server machine, which is what happens when you submit a job to FP Web, then the composition picks up the date and time from that remote composition machine. Changing the system clock on your local machine will only affect compositions preformed locally on that machine; it can't possibly have any effect on a composition which occurs on a different machine.

 

Obviously the composition machines running jobs for FP Web are set up with the actual current date and time. I would expect that these machines are set for Pacific Time, since we're a California-based company.

Hrm. I dunno. I defer to Sweet and Dan on this one.

I'm unsure as to where FusionPro picks up its date & time data.

 

Stupid question that I forgot to ask - you are using FusionPro Desktop, right? (Cause if it's being composed somewhere else, you'll need to change the date/time there. Forgive me if that seems like the condescending "Is your computer plugged in?" tech support question.)

Well, no, actually, it's not a stupid question at all. In fact, it's exactly the right question to ask. The context under which you are running a job is absolutely relevant and crucial to diagnosing any issues. See my signature.

Yes, I am using FusionPro Desktop on my Mac which is plugged in. But I think it is my rule. I don't think I did it right.

Thanks for your suggestions, however.

 

I suppose if Dan or David took a look at my rule, they could tell me if I applied it correctly.

One question I had for Dan, which could be obvious is, what exact rule information goes into the "rule_Copyright" rule. I assumed it was this:

"return FormatDate(Today(), "yyyy");" but he did not specify.

Thanks,

Rayed

Like I said earlier, you can use the Today() function, and it is guaranteed to return the current date and time, on the machine where the composition is being performed. I'm not sure why my assurances in this regard aren't satisfying, but you also now have empirical results that back this up: specifically, you saw that changing the system time on your local machine affects the date returned for a local composition, but not for a remote composition (via FP Web).

 

And as I also noted earlier, instead of always using the "current" date at the time of composition, you might want to hard-code a specific year into that function, in case you happen to be composing a job which is intended for printing or mailing at a later date than when the composition is performed. But you did not seem interested in this advice either.

 

In the end, exactly what logic should go into your rules depends on your business requirements, and I can't tell you what those are.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...