Jump to content

Formatting phone numbers on BC


jpreve

Recommended Posts

Hi,

 

I need help with a script to format phone numbers in a business card for DSF. Please see the examples below to see what I’m trying to accomplish. FYI, the Toll-Free number will be a pick list in DSF, and I think I figured out how to suppress if someone chooses none, by opening the xml file. I just need to figure out this script first.

 

Example 1: (all 4 numbers used: Office & Cell on 1st line and Fax & Toll-Free on 2nd line.)

Office: (000) 000-0000 • Cell: (000) 000-0000

Fax: (000) 000-0000 • Toll-Free: (000) 000-0000 ext.0000

 

Example 2: (if 3 numbers used)

Office: (000) 000-0000 • Cell: (000) 000-0000 • Fax: (000) 000-0000

and all other variations of 3 numbers

 

Example 3: (if 2 numbers used)

Office: (000) 000-0000 • Toll-Free: (000) 000-0000 ext.0000

and all other variations of 2 numbers

 

Example 1: (if 1 number used)

Office: (000) 000-0000

and all other variations of 1 number

 

Basically, I need to suppress what is empty, and keep the phone numbers on 1 line if it fits and break to a new line if doesn’t fit.

I need the bullet to suppress at the beginning and end of a line. The bullet needs to be a different color: PANTONE 201.

 

Here is what I have so far:

 

var Office = Rule(“Office Rule”) // Or Rule(“Office Rule)

var Fax = Rule(“Fax Rule”);

var Cell = Rule(“Cell Rule”);

var TollFree = Field(“Toll-Free”);

var Ext = Field(“ext”);

 

 

var numbers = [“Office: “ + Office,”Cell: “ + Cell,”Fax: “ + Fax,”Toll-Free: “ + TollFree,”ext.” + Ext];

 

return numbers.filter(function(m){return m.match(/.*\s(?=.)/);}).join(“ • ”);

 

 

 

Please Help!!!

 

Thanks,

jpreve :)

Link to comment
Share on other sites

You don't need a rule. Just type each line into the Text Editor, with the bullet character, the label ("Office: " etc.), and the variable for each rule, then select all, click the Paragraph button, check the "Suppress if" box, and change the drop-down to "Containing empty variables."
Link to comment
Share on other sites

I've tried this already, when one number from one line is empty, the whole line suppresses. (Remember this is going to DSF.) When there is less than 4 numbers (see examples 2&3). I want the Fax to move up, but it leaves the bullet at the end (part of the Toll-Free #. I need the bullet to suppress at beginning and end of the line.

example: Office: (000) 000-0000 • Cell: (000) 000-0000 • Fax: (000) 000-000 •

 

The bullet is PANTONE 201 C and all other copy is black.

I used a hide label rule when I tried it this way for each Label.

 

if (Rule("Cell Rule") == "")

return "";

else

return '<color name = "PANTONE 201 C"> • </color>' + 'Cell: '+Rule("Cell Rule");

Link to comment
Share on other sites

I've tried this already, when one number from one line is empty, the whole line suppresses. (Remember this is going to DSF.) When there is less than 4 numbers (see examples 2&3). I want the Fax to move up, but it leaves the bullet at the end (part of the Toll-Free #. I need the bullet to suppress at beginning and end of the line.

example: Office: (000) 000-0000 • Cell: (000) 000-0000 • Fax: (000) 000-000 •

 

The bullet is PANTONE 201 C and all other copy is black.

I used a hide label rule when I tried it this way for each Label.

 

if (Rule("Cell Rule") == "")

return "";

else

return '<color name = "PANTONE 201 C"> • </color>' + 'Cell: '+Rule("Cell Rule");

Yes, sorry, that "Suppress if" won't work if there's more than one on a line. You need to do something like this:

http://forums.pti.com/showpost.php?p=10507&postcount=6

 

For instance:

var numbers = 
{
   Office: Rule("Office Rule"),
   Cell: Rule("Cell Rule"),
   Fax: Rule("Fax Rule"),
   "Toll-Free": Rule("Toll-FreeRule"),
};

var result = [];
for (var label in numbers)
   if (numbers[label])
       result.push(label + ": " + numbers[label]);

var delim = '<color name = "PANTONE 201 C"> • </color>';

if (result.length == 4)
   return result.slice(0,2).join(delim) + '<br>' + result.slice(2).join(delim);
//else
return result.join(delim);

Note that this calls a rule for each of the four numbers, including the toll-free number. The regular "Change phone format" XML Template rule should be able to handle an extension in the number.

Link to comment
Share on other sites

Still doesn't work. I'm still getting a bullet at the end of the line, (behind fax) and "<br>" is showing up in the preview. Also, the bullets are not changing to PANTONE 201. I can't believe formatting a business card can be so complex. :confused::confused::confused:

Let's start over: My card should view like the following samples:

 

All 4 numbers used:

Office: (000) 000-0000 Cell: (000) 000-0000

Fax: (000) 000-0000 Toll-Free: 1-800-000-000 ext.0000

No Cell: (if all 3 numbers do not fit on one line than it needs to go the next line, with no bullet in front or end of the line.)

Office: (000) 000-0000 Fax: (000) 000-0000

Toll-Free: 1-800-000-000 ext.0000

 

No Fax: (same as previous sample.)

Office: (000) 000-0000 Cell: (000) 000-0000

Toll-Free: 1-800-000-000 ext.0000

 

No Toll-Free or ext: (Add a bullet before Fax, and No bullet after Fax)

Office: (000) 000-0000 Cell: (000) 000-0000 Fax: (000) 000-0000

FYI: The Toll-Free number is going to be a pick list in digital storefront, with 4 numbers to choose from, and there will be a separate field for the ext.#.

 

Please let me know if you need anymore info. Really appreciate your help!

 

Sincerely,

jpreve :)

Link to comment
Share on other sites

Still doesn't work. I'm still getting a bullet at the end of the line, (behind fax) and "<br>" is showing up in the preview.

You need to ensure that "Treat returned strings as tagged text" is checked in your rule editor. That will resolve the issue of tags (<br>) showing up in the preview.

 

Also, the bullets are not changing to PANTONE 201.

Have you defined the color within FusionPro (FusionPro > Advanced > Colors)? Is the color defined as "PANTONE 201" or "PANTONE 201 C"? You need to make sure your code is referencing the color by the name you have defined within FusionPro. You can also define the color within the rule itself like so:

new FusionProColor('PANTONE 201 C', 0, 100, 100,0)

The above would result in "PANTONE 201 C" having a build of 0/100/100/0 (C/M/Y/K respectively).

 

Let's start over: My card should view like the following samples:

 

All 4 numbers used:

Office: (000) 000-0000 Cell: (000) 000-0000

Fax: (000) 000-0000 Toll-Free: 1-800-000-000 ext.0000

No Cell: (if all 3 numbers do not fit on one line than it needs to go the next line, with no bullet in front or end of the line.)

Office: (000) 000-0000 Fax: (000) 000-0000

Toll-Free: 1-800-000-000 ext.0000

 

No Fax: (same as previous sample.)

Office: (000) 000-0000 Cell: (000) 000-0000

Toll-Free: 1-800-000-000 ext.0000

 

No Toll-Free or ext: (Add a bullet before Fax, and No bullet after Fax)

Office: (000) 000-0000 Cell: (000) 000-0000 Fax: (000) 000-0000

FYI: The Toll-Free number is going to be a pick list in digital storefront, with 4 numbers to choose from, and there will be a separate field for the ext.#.

So it sounds like you don't care as much about adding a break when there are 4 numbers, but what you really want to do is to put the "Toll-Free" number on its own line when there's more than one other number being used while restricting the first line to only 2 numbers. To do that, you can modify Dan's code to this:

var numbers = 
{
   Office: Rule("Office Rule"),
   Cell: Rule("Cell Rule"),
   Fax: Rule("Fax Rule"),
   "Toll-Free": Rule("Toll-FreeRule"),
};


var result = [];
for (var label in numbers)
   if (numbers[label])
       result.push(label + ": " + numbers[label]);

var delim = '<color name = "PANTONE 201 C"> • </color>';

if ([color="Red"]result.length > 2 && numbers['Toll-Free'][/color])
   return [color="red"]result.splice(0,2).join(delim) + '<br>' + result.join(delim)[/color];
//else
return result.join(delim);

Since the length of the 'result' array hinges on whether or not the results of your phone number rules are actually empty or not, you'll need to make sure that they are returning empty strings when the field is empty.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...