If you have a single variable and multiple states, or conditions, it can be
in, there is a better way than several if or if/else statements.  The switch
statements takes a single variable and finds the matching case.  See my
example below.  For people coming from Java, note that JavaScript can use
both string and numbers.

 

switch (Field("ZIP")) {

case "10007":  return "646 587";

    break; // technically not needed because the return jumps out of the
rule, but good practice.

case "02199":   return "617 425";

    break;

// insert more case statements here

default:

    return "";

}

 

There are a couple of things to know:  If you have to case statements that
are the same, it will go to the first one and start running from there.
Once it finds a match with the case statement it will run all the code
after, unless you have a break (or a return); you can omit breaks for some
very specific results to get effect, but make sure that is your intent.
Once the code hits a break it will jump to the end of the switch statement
and resume processing from there.

 

Cheers.

 

From: Christopher Reilley [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 18, 2007 7:22 AM
To: FusionPro Users Forum
Subject: [fusionpro] script for coding first 6 digits based on zip

 

I am attempting to script a rule that will hard code the first six digits of
a phone field based on the zip code, in order to allow the client to only
enter the last four digits after they have selected the office they are
located in.

 

My script looks like this:

if (Field("Zip") == "10007")

return "646 587";

else

return " ";

 

if (Field("Zip") == "02199")

return "617 425";

else

return " ";

 

if (Field("Zip") == "60611")

return "312 266";

else

return " ";

 

if (Field("Zip") == "10011")

return "212 463";

else

return " ";

 

if (Field("Zip") == "94102")

return "415 345";

else

return " ";

 

. but I am not getting any return. I am certain it must be a simple
Javascript error, but cannot find it. Any ideas?

Thanks in advance!

 

Christopher Reilley
Business Systems Analyst - Printing
W.B. Mason Co.
59 Centre Street, Brockton, MA 02303
 <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED] 

(p) 508.436.8693 
(f) 508.436.5090 
(c) 781.308.2083  

 

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Calling all FP Web
Users! Do you have a question or lots of knowledge to share about FusionPro
Web? If so, join our Printable Web to Print Users' Forum today! Send email
to [EMAIL PROTECTED] to find out how!
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -- Users of
FusionPro Desktop have unlimited free email support. Contact Printable
Support at [EMAIL PROTECTED] -- View FusionPro Knowledge Base,
FusionPro Samples at www.printable.com/vdp/desktop.htm -- You are currently
subscribed to fusionpro as: [EMAIL PROTECTED] To unsubscribe
send a blank email to [EMAIL PROTECTED] --
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Calling all FP Web
Users! Do you have a question or lots of knowledge to share about FusionPro
Web? If so, join our Printable Web to Print Users' Forum today! Send email
to [EMAIL PROTECTED] to find out how!
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -- Users of
FusionPro Desktop have unlimited free email support. Contact Printable
Support at [EMAIL PROTECTED] -- View FusionPro Knowledge Base,
FusionPro Samples at www.printable.com/vdp/desktop.htm -- You are currently
subscribed to fusionpro as: [EMAIL PROTECTED] To unsubscribe
send a blank email to [EMAIL PROTECTED] -- --
Note: All e-mail sent to or from this address will be received or otherwise
recorded by the e-mail recipients of this forum. It is subject to archival,
monitoring or review by, and/or disclosure to someone other than the
recipient. Our privacy policy is posted on www.printplanet.com -- -- Note:
All e-mail sent to or from this address will be received or otherwise
recorded by the e-mail recipients of this forum. It is subject to archival,
monitoring or review by, and/or disclosure to someone other than the
recipient. Our privacy policy is posted on www.printplanet.com -- 

<<image001.gif>>

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- 
Calling all FP Web Users!

Do you have a question or lots of knowledge to share about FusionPro Web?

If so, join our Printable Web to Print Users' Forum today!

Send email to [EMAIL PROTECTED] to find out how! 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-


--
Users of FusionPro Desktop have unlimited free email support. Contact Printable 
Support at [EMAIL PROTECTED] 
--
View FusionPro Knowledge Base, FusionPro Samples at
www.printable.com/vdp/desktop.htm

--
You are currently subscribed to fusionpro as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
--



--
Note:  All e-mail sent to or from this address will be received or otherwise 
recorded by the e-mail recipients of this forum. It is subject to archival, 
monitoring or review by, and/or disclosure to someone other than the recipient. 
Our privacy policy is posted on www.printplanet.com
--

Reply via email to