Views:

Scenario Overview

In this scenario the business requirement is to format the main telephone number on the Account entity. The requirement is that if the phone number is 7 or 10 characters long we need to apply the formatting rules else leave the phone number as is.

7 Digit Rule
1234567 -> 123-4567

10 Digit Rule
1234567890 -> (123) 456-7890

N52 Formula Manager Solution

The Formula Manager solution works like this,

  • We create a formula to execute on the 'Create & Update' event of the Account entity
  • We set it only to execute when the Main Phone number gets set initially or updated 
  • It first cleans the telephone number by removing all non digits
  • it then checks to see how many digits are in the phone number
  • Depending on the number of digits it applies a Regex which in effect is the formatting rule or it leaves it as is
  • It places the result back into the Main Phone field

N52 Formula Manager Steps

The following set of steps will set this formula up for you,

  • Create a new formula of type 'Save To Current Record'
  • Set the Source Entity to 'Account'
  • Set the Source Property field to 'Main Phone'
  • Set the Target Property field to 'Main Phone
  • Copy & paste the formula from below
  • Click save & test on an Account record

Formula

SmartFlow(

   SetVar('CleanedPhoneNumber', RegexReplace([account.telephone1], «\D», '')), 
   
   SmartFlowReturn( 
          Case( CountCharacters(GetVar('CleanedPhoneNumber')),

              When(7), Then (RegexReplace(GetVar('CleanedPhoneNumber'), «(\d{3})(\d{4})», «$1-$2»)),

              When(10), Then (RegexReplace(GetVar('CleanedPhoneNumber'), 
                                         «(\d{3})(\d{3})(\d{4})», «($1) $2-$3»)),

              Default([account.telephone1])
                                )
                 )
)