Welcome to DirectSmile

Hide telephone label

link this post written on 02/09/2015
  • To top

Hi

 

I a very new to DSM and i am am having an issue whereas i am creating a business card and want to hide ie Tel: +44 (0) so when a telphone number is enterd it returns the hiden label plus the number and blank it emptyi have tried using js rule but this does not work in DSM help please.

 

if (Field("Mobile") == "")

return "";

else

return 'Mobile: +44 (0)'+Field("Mobile");

 

 

Regards

 

Carmichael

link this post written on 03/09/2015
  • To top

Hi Carmichael

You script in javascript is very easy. You should to create a new variable in your indesign, for example MobileScript and insert this script:

function MobileScript_Value()
{
if (RS("Mobile")== ""){
    return "";
}
else{
    return "Mobile: +44 (0)" + RS("Mobile");
}
}

Kind regards

Jaume

The author has edited this post (on 03/09/2015)
link this post written on 03/09/2015
  • To top

Thanks so much i will give this try.

 

Regards

 

Carmicael

link this post written on 01/10/2015
  • To top

Hi Jaume

I am working in storefront studio and have applied this script but this gives me an script error.

 

!!ScriptError in Line 3 Column 0: Item cannot be found in the collection corresponding to the requested name or ordinal

 

Regards

 

Carmichael

link this post written on 02/10/2015
  • To top

I have a very similar situation with the business cards I've been working on lately. Each phone number is led by a label, like "Office 123.456.7890." You have to use regular expressions, or regex, for this way of doing things. These are some good resources: X X X

Here's the code I used for my business cards:

 

function numbers(){
out = ""
num = VAR.GetS("Cell_Phone", ""); if(num.length>0) out += "Cell " + phone(num) + "\n"; else out = "" + out;
num = VAR.GetS("Fax", ""); if(num.length>0) out += "Fax " + phone(num) + "\n"; else out = "\n" + out;
num = VAR.GetS("Office_Phone", ""); if(num.length>0) out += "Office " + phone(num) + "\n"; else out = "" + out;
num = VAR.GetS("Toll_Free_Number", ""); if(num.length>0) out += "Toll Free " + phone(num); else out = "" + out;
return out; }

 

VAR.GetS

says which variable data field to use. It is represented by "num" here, so when I want the field to appear, I write "num."

if(num.length>0)

means that if the field is longer than zero characters (if it's in use) then the following phrase will be used:

"Cell " + phone(num) + "\n"

Which would appear on the printed card as "Cell 123.456.7890" with a line break after, to start the next number on a new line.

else out = ""

means that if the field is not longer than zero characters (the field is left empty) then nothing will be entered.

 

the phone(     ) section refers to a second piece of javascript I use to format my phone numbers on the back end. It might be useful to you- your users won't have to type in the exact format you want on the front end, because you can use this script to remove their formatting and put in your own. Here, it's set up to display phone numbers as 123.456.7890

 

function phone(number){
   tmp = ""; div = ".";
   if( number.length>0 ){
       tmp = number.replace(/\D/g, "");
       var len = tmp.length;
       tmp = tmp.split("");
       tmp.splice(len-7,0, div);
       tmp.splice(len-3,0, div);
      tmp = tmp.join("");
  }
  return tmp;
}

 

function phone(number){

establishes the tag to use up in the first chunk of js when you want this script to be applied.

tmp = ""; div = ".";

says what characters (or lack thereof, for tmp) will be inserted into the number.

tmp = number.replace(/\D/g, "");

takes all the formatting out of the phone number submitted by the user by replacing them with nothing, since tmp = nothing. So (123) 456-7890 would become 1234567890

tmp.splice(len-7,0, div);
tmp.splice(len-3,0, div);

these say where to splice in characters. In this case, periods, because div = .

the end result is that no matter how the user inputs the phone number, it's spit out on the other end in the same consistent format you define.

 

I hope this is helpful!

link this post written on 06/10/2015
  • To top

Hi Sheri

 

This is indeed a big help thanks for your detailed explanation this make my life easier.

 

Cheers

 

Carmichael         

  • Statistics: 6 Posts | 22 Visits
created by mixxt
  • v1.1.1
  • (highfive)