Jump to content

FusionPro Rule Template Updates


Recommended Posts

I have clients that use the Change Phone Format Rule template constantly. However, many of them need to convert the template to JavaScript and edit the base rule because two of the formatting options do not include a space between the area code and the phone number. Is there a way to modify the base rule in the template itself to include the space in these formats so that the JavaScript doesn't need to be updated every time the template is used?

PhoneFormat.png.265d8d0fc1ea8e9f289ff34587b24ce4.png

Link to comment
Share on other sites

I have clients that use the Change Phone Format Rule template constantly. However, many of them need to convert the template to JavaScript and edit the base rule because two of the formatting options do not include a space between the area code and the phone number. Is there a way to modify the base rule in the template itself to include the space in these formats so that the JavaScript doesn't need to be updated every time the template is used?

 

You shouldn't have to convert the entire rule and edit the original JavaScript code to add a space. You could simply create a "wrapper" rule to return the modified string:

return Rule("Change phone format Rule").replace(')', ') ');

 

I guess if you really wanted to, you could update the XML that creates that rule (though I would recommend creating a new file instead). In addition to making it a new "rule" I would also strongly recommend adding a checkbox to the rule to toggle the space rather than add the space to the source and end up in the same predicament when you decide a space isn't needed. The resulting file would be placed in "/Library/Application Support/PTI/FusionPro/Plug-ins/TemplateXML" on each of the machines you want to add the new rule to.

 

<?xml version="1.0" encoding="ISO-8859-1" ?>
<template_rule name="*MODIFIED* Change phone rule" version="1.0" type="text" taggedtext="false">
<rulename language="en-US">[MODIFIED] Change phone format Rule</rulename>
<rulename language="de">Regel zum Ändern des Telefonformats</rulename>
<rulename language="fr">Règle Changer le format téléphonique</rulename>
<rulename language="es">Regla Cambiar formato de teléfono</rulename>
<rulename language="it">Regola modifica formato numero di telefono</rulename>
<Comment language="en-US">This rule has been MODIFIED to change the value of a phone number field to a particular format of your choice.</Comment>
<Comment language="de">Mit dieser Regel wird der Wert eines Telefonnummernfeldes in ein Format Ihrer Wahl geändert.</Comment>
<Comment language="fr">Cette règle va changer la valeur d’un champ de numéro de téléphone en un format particulier de votre choix.</Comment>
<Comment language="es">Esta regla cambiará el valor del campo de un número de teléfono a un formato que usted elija.</Comment>
<Comment language="it">La regola consente di cambiare il valore di un campo numero di telefono in un campo con qualsiasi formato.</Comment>
<Description language="en-US">Please specify the appropriate values.</Description>
<Description language="de">Geben Sie die entsprechenden Werte an.</Description>
<Description language="fr">Veuillez spécifier les valeurs appropriées.</Description>
<Description language="es">Especifique los valores que correspondan.</Description>
<Description language="it">Specificare i valori appropriati.</Description>

<fieldlist>
 <field type="FIELDLIST" required="true">
   <fieldname>Var1</fieldname>
   <prompt language="en-US">Choose the phone field:</prompt>
   <prompt language="de">Feld "Telefon" wählen:</prompt>
   <prompt language="fr">Choisissez le champ de téléphone :</prompt>
   <prompt language="es">Elija el campo de teléfono:</prompt>
   <prompt language="it">Scegliere il campo telefono:</prompt>
   <value></value>
 </field>

<field type="PICKLIST" subtype="ListBox" required="true">
    <fieldname>CaseSelection</fieldname>
    <prompt language="en-US">Choose the format:</prompt>
    <prompt language="de">Wählen Sie das Format:</prompt>
    <prompt language="fr">Choisissez le format :</prompt>
    <prompt language="es">Elija el formato:</prompt>
    <prompt language="it">Scegliere il formato:</prompt>
    <value></value>
   <picklist>
       <item><prompt>123.456.7890</prompt><value>Format 1</value></item>
       <item><prompt>123-456-7890</prompt><value>Format 2</value></item>
       <item><prompt>(123)456-7890</prompt><value>Format 3</value></item>
       <item><prompt>(123)456.7890</prompt><value>Format 4</value></item>
   </picklist>
</field>

 <field type="CHECKBOX">
   <fieldname>includeSpace</fieldname>
   <prompt language="en-US">Space after area code when using parentheses?</prompt>
   <prompt language="de">De ruimte na het netnummer bij het gebruik van haakjes?</prompt>
   <prompt language="fr">Espace après le code de la zone lors de l'utilisation parenthèses?</prompt>
   <prompt language="es">¿Espacio después de código de área al utilizar paréntesis?</prompt>
   <prompt language="it">Spazio dopo prefisso quando si utilizza parentesi?</prompt>
   <value>0</value>
 </field>

</fieldlist>

<code>


if(CaseSelection == "Format 1")
{
var formatStyle01 = "$1.$2"; 			//simple 7 digit phone
var formatStyle02 = "$1.$2.$3";			//simple 10 digit phone
var formatStyle03 = "+$1 $2.$3.$4";		//10 digit phone starts with 1
var formatStyle04 = "$1.$2.$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 $2.$3.$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1.$2 ext.$3";		//7 digit phone with extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}





if(CaseSelection == "Format 2")
{
var formatStyle01 = "$1-$2"; 			//simple 7 digit phone
var formatStyle02 = "$1-$2-$3";			//simple 10 digit phone
var formatStyle03 = "+$1 $2-$3-$4";		//10 digit phone starts with 1
var formatStyle04 = "$1-$2-$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 $2-$3-$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1-$2 ext.$3";		//7 digit phone with extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}





if(CaseSelection == "Format 3")
{
var formatStyle01 = "$1-$2"; 			//simple 7 digit phone
var formatStyle02 = "($1)$2-$3";			//simple 10 digit phone
var formatStyle03 = "+$1 ($2)$3-$4";		//10 digit phone starts with 1
var formatStyle04 = "($1)$2-$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 ($2)$3-$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1-$2 ext.$3";		//7 digit phone with extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}






if(CaseSelection == "Format 4")
{
var formatStyle01 = "$1.$2"; 			//simple 7 digit phone
var formatStyle02 = "($1)$2.$3";			//simple 10 digit phone
var formatStyle03 = "+$1 ($2)$3.$4";		//10 digit phone starts with 1
var formatStyle04 = "($1)$2.$3 ext.$4";		//10 digit phone with extension
var formatStyle05 = "+$1 ($2)$3.$4 ext.$5";	//10 digit phone starts with 1 with extension
var formatStyle06 = "$1.$2 ext.$3";		//7 digit phone with extension

var thisNumber = Field(Var1);

return formatNumber(Trim(thisNumber));
}









//////////////////////////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE ///////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

return formatNumber(Trim(thisNumber));

function formatNumber(number01){

var format = [formatStyle01,formatStyle02,formatStyle03,formatStyle04,formatStyle05,formatStyle06].map(function(s){ return includeSpace ? s.replace(')', ') ') : s; });

var pattern01 = /^(\d{3})[^\d]*(\d{4})$/;   						
//   //2201727 or 220-1727 or 220- 1727
var pattern02 = /^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;   				
// 8002201727 or 800-220-1727 or (800)220-1727 or (800) 220-1727
var pattern03 = /^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/;   			
// 18002201727 or 1-800-220-1727 or +1 (800) 220-1727
var pattern04 = /^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;		
// 800-220-1727 ext 12345 or (800) 220-1727 ext 12345
var pattern05 = /^\+?(\d{1})[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;	
// 1-800-220-1727 ext 12345 or +1 (800) 220-1727 ext 12345
var pattern06 = /^(\d{3})[\D]*(\d{4})\D*[x#n]\D*(\d+)$/;   				
// 2201727 ext 1234 or 220-1727 ext 1234 or 220- 1727 ext 1234
var patternEndExt = /(.)[x#n](.)/;
var patternStart1 = /^[\D]*[1]/;

if(number01.match(pattern01)){
	number01 = number01.replace(pattern01, format[0]);
	return number01;
} else if(number01.match(pattern02)){
	number01 = number01.replace(pattern02, format[1]);
	return number01;
} else if(number01.match(pattern03)){
	if (number01.match(patternStart1)){
		number01 = number01.replace(pattern03, format[2]);
		return number01;
	} else {
		return number01;
	}
} else if(number01.match(pattern04)){
		number01 = number01.replace(pattern04, format[3]);
		return number01; 
} else if(number01.match(pattern05)){
		number01 = number01.replace(pattern05, format[4]);
		return number01;
}  else if(number01.match(pattern06)){
		number01 = number01.replace(pattern06, format[5]);
		return number01;
} else {
	//return "no match any pattern";
	return number01;
}	
}





</code>
</template_rule>

Link to comment
Share on other sites

Thanks. Where is the RulesTemplate Script Script File located so that I can edit it?

The XML template rules aren't in the RuleTemplates.English.js file; they're in the TemplateXML folder. Its location is platform specific:

  • On Mac: /Library/Application Support/PTI/FusionPro/Plug-ins/TemplateXML
  • On Windows (64-bit): C:\Program Files (x86)\PTI\FusionPro\Plug-ins\TemplateXML
  • On Windows (32-bit): C:\Program Files\PTI\FusionPro\Plug-ins\TemplateXML

However, I don't recommend editing the files there. For one thing, if you re-install or install a new version of FusionPro, your changes will be overwritten. Instead, I recommend adding a new file in there. You can copy and paste the existing "Change phone format.xml" file with a new name; just remember that, in addition to the changes you want to make to the rule syntax, you need to also update the <template_rule> tag on line 2 to give the rule a unique name, perhaps something like "Randy's Change phone format Rule".

Edited by Dan Korn
Link to comment
Share on other sites

I would also strongly recommend adding a checkbox to the rule to toggle the space rather than add the space to the source and end up in the same predicament when you decide a space isn't needed.

Sure, although if you're going to do that, why not just have an option to specify the delimiter (dash, dot, or something else), and another option to specify whether to use parentheses for the area code, and then the option for the space? Frankly, there's a lot about our built-in XML template rule that could be improved; it's on my rainy day list.

Link to comment
Share on other sites

Sure, although if you're going to do that, why not just have an option to specify the delimiter (dash, dot, or something else), and another option to specify whether to use parentheses for the area code, and then the option for the space? Frankly, there's a lot about our built-in XML template rule that could be improved; it's on my rainy day list.

I suppose I'm just hesitant to alter those templates too much. (Though you could argue that simply adding a space to the replacement strings would have kept the code closer to the original than the changes that I made do.) But your comment reminded me of this gif.

Link to comment
Share on other sites

  • 1 month later...

Great question, Randy! :p

 

As one of those clients of yours who use the phone format rule constantly - and constantly update it - I'm definitely going to make a new copy of the rule with our common formats. Thanks Don, Ste and Dan for the thoughts on how to go about it.

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