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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old March 14th, 2012, 02:50 PM
traba5058 traba5058 is offline
Regular Contributor
 
Join Date: Jan 2012
Location: Atlanta, GA
Posts: 77
Default Re: Write a case rule with exceptions

Dan,

I created a new rule in Fusion Pro and pasted in your code

Code:
var result = ToTitleCase(Field("Full Name"););
var Exceptions = [ "I", "II", "III", "IV" ];
for (var i in Exceptions)
{
    var re = RegExp("\\b" + Exceptions[i] + "\\b", "gi");
    result = result.replace(re, Exceptions[i]);
}
return result;
Now I am getting an error when I validate it:

line 1:Syntax Error: missing ) after argument list.

Can you help me?
Reply With Quote
  #12  
Old March 14th, 2012, 03:43 PM
ThomasLewis's Avatar
ThomasLewis ThomasLewis is offline
Senior Contributor
 
Join Date: Feb 2011
Posts: 233
Default Re: Write a case rule with exceptions

There's an extra semicolon in the first line.
It should read:
var result = ToTitleCase(Field("Full Name"));
Reply With Quote
  #13  
Old March 14th, 2012, 05:01 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,671
Default Re: Write a case rule with exceptions

Quote:
Originally Posted by ThomasLewis View Post
There's an extra semicolon in the first line.
It should read:
var result = ToTitleCase(Field("Full Name"));
Sorry about that. I edited my post to fix it. Here's the corrected version of the full rule:
Code:
var result = ToTitleCase(Field("Full Name"));
var Exceptions = [ "I", "II", "III", "IV" ];
for (var i in Exceptions)
{
    var re = RegExp("\\b" + Exceptions[i] + "\\b", "gi");
    result = result.replace(re, Exceptions[i]);
}
return result;
__________________
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
  #14  
Old June 19th, 2012, 01:34 PM
strido's Avatar
strido strido is offline
Regular Contributor
 
Join Date: Apr 2011
Posts: 82
Default Re: Write a case rule with exceptions

Sorry to resurrect the thread -

I'm having a bit of an issue here, using the typical ProperCase rule:

Quote:
var Var1 = "AgencyName";
return ToTitleCase(Field(Var1));
Now, we have two clients that have capital letters in their name - ABC Corporation for instance. What's the syntax so it doesn't come out Abc Corporation? I tried the exceptions listed above but couldn't get that to work.

My client only has the two companies that this is affected by, so it's really not a matter of listing out every possible permutation. We'll be notified if any new ones arise, so it'll just be a matter of plugging them in.

Long story short, I'd like the ProperCase to continue, just not when the letters ABC are involved....
__________________
-Windows 7 Professional - Adobe CS5.5 -Acrobat Professional X -FusionPro Designer 8.2.5
Reply With Quote
  #15  
Old June 19th, 2012, 02:00 PM
ThomasLewis's Avatar
ThomasLewis ThomasLewis is offline
Senior Contributor
 
Join Date: Feb 2011
Posts: 233
Default Re: Write a case rule with exceptions

Using an array the way Dan suggested is the easiest to manage when there are a lot of variables or when you know you'll be adding more in the future.

If you have a few static values you are dealing with or if you don't want to deal with arrays and loops you can use a simple if/else rule:

Code:
var Var1 = Field("AgencyName").toLowerCase();

if (Var1 == "abc corporation")
	return "ABC Corporation";
else if (Var1 == "pti")
	return "PTI";
else
	return ToTitleCase(Var1);
In this case I am pre-converting the Field value to lowercase then checking just to be safe as it has to be an exact match.
Reply With Quote
  #16  
Old June 19th, 2012, 03:30 PM
strido's Avatar
strido strido is offline
Regular Contributor
 
Join Date: Apr 2011
Posts: 82
Default Re: Write a case rule with exceptions

That didn't seem to want to work....



I'm still getting the first letter Upper Case and the 2nd Lower. It should say "MW" both upper....
__________________
-Windows 7 Professional - Adobe CS5.5 -Acrobat Professional X -FusionPro Designer 8.2.5
Reply With Quote
  #17  
Old June 19th, 2012, 04:10 PM
ThomasLewis's Avatar
ThomasLewis ThomasLewis is offline
Senior Contributor
 
Join Date: Feb 2011
Posts: 233
Default Re: Write a case rule with exceptions

As stated, it has to be an exact match to the entire string, the only exception being that it's all going to be in lowercase to get around any inconsistencies with case.

Code:
if (Var1 == "mw financial")
	return "MW Financial";
mw Financial, Mw financial, MW Financial, would all work because they are forced to lowercase before being compared to == "mw financial".

The misspelled "mw finacail" would not work. You would have to put in another else if to handle misspellings. This is where Dan's suggestion of using an array and loop would be preferable as you could add in lots of variants easily.

Alternatively you could do something like this:

Code:
if (Var1.substring(0,3) == "abc")
	return "ABC Corporation";
else if (Var1.substring(0,2) == "mw")
	return "MW Financial";
This just checks for a match of the first few characters and doesn't worry about anything after. So the misspelling later in the word would still be a match. The only problem with this would be if you had a few agencies that started with the same letters.
Reply With Quote
  #18  
Old June 20th, 2012, 08:38 AM
strido's Avatar
strido strido is offline
Regular Contributor
 
Join Date: Apr 2011
Posts: 82
Default Re: Write a case rule with exceptions

That'll do! Thanks!
__________________
-Windows 7 Professional - Adobe CS5.5 -Acrobat Professional X -FusionPro Designer 8.2.5
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 10:07 PM.


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