Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Displaying Phone Numbers in a specific way

  1. #1
    tanhaa is offline Sugar Community Member
    Join Date
    Jul 2006
    Posts
    38

    Default Displaying Phone Numbers in a specific way

    Background:

    We enter all our phone numbers in the leads section without any punctuations or other characters, a simple string of numbers:
    e.g. 1112223333

    However, I would like to show the phone numbers in this manner: (111) 222-3333

    I can do the code to show the phone number like this, but I'm not sure which files to edit where I can work with lets say, the "phone_work" variable and turn it into the format I want to display it in.


    Any assistance in terms of being pointed in the right direction would be greatly appreciated.


    Amit Malhotra

  2. #2
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Displaying Phone Numbers in a specific way

    I made something for this exact purpose a while back.

    I haven't updated it for the more recent versions of Sugar, but it should work.

    Here is the thread where I posted it (look at the last message for most recent set of files):

    http://www.sugarcrm.com/forums/showt...9&page=2&pp=10
    Regards,

    Angel Magaņa
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  3. #3
    tanhaa is offline Sugar Community Member
    Join Date
    Jul 2006
    Posts
    38

    Default Re: Displaying Phone Numbers in a specific way

    Quote Originally Posted by Angel
    I made something for this exact purpose a while back.

    I haven't updated it for the more recent versions of Sugar, but it should work.

    Here is the thread where I posted it (look at the last message for most recent set of files):

    http://www.sugarcrm.com/forums/showt...9&page=2&pp=10
    Hi Angel,

    I went through the thread... two questions:

    first of all, thank you for replying

    secondly question 1. This won't effect the visibility of the phone numbers that are already in the system but rather phone numbers that are being entered through the EDIT VIEW or CREATE LEAD/CONTACT section right?
    question 2. I mainly import leads in huge numbers with phone numbers already formatted as a string with no non-numerical characters in the middle, will this still work? I should probably look at the code before I ask these questions, but just wanted to get them quickly off my chest.

    Hope to hear from ya soon! Thanks in advance.


    Amit Malhotra

  4. #4
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Displaying Phone Numbers in a specific way

    Quote Originally Posted by tanhaa
    Hi Angel,

    I went through the thread... two questions:

    first of all, thank you for replying

    secondly question 1. This won't effect the visibility of the phone numbers that are already in the system but rather phone numbers that are being entered through the EDIT VIEW or CREATE LEAD/CONTACT section right?
    question 2. I mainly import leads in huge numbers with phone numbers already formatted as a string with no non-numerical characters in the middle, will this still work? I should probably look at the code before I ask these questions, but just wanted to get them quickly off my chest.
    Happy to help.

    1. Correct. It will not affect the already existing numbers, but that can be done using a similar principle through a PHP script that directly updates the MySQL database. If I get a moment over the weekend, I can whip one up that does it.

    2. No, it won't do it for imported records. That would have to be done prior to importing it, or via the import engine.

    There is another possible way of handling it which would make all of this a moot point, but that's a bit more involved. I'll give it a look over the weekend if time permits.

    No prob about the questions. Better to ask than to assume.
    Regards,

    Angel Magaņa
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  5. #5
    tanhaa is offline Sugar Community Member
    Join Date
    Jul 2006
    Posts
    38

    Default Re: Displaying Phone Numbers in a specific way

    Quote Originally Posted by Angel
    Happy to help.

    1. Correct. It will not affect the already existing numbers, but that can be done using a similar principle through a PHP script that directly updates the MySQL database. If I get a moment over the weekend, I can whip one up that does it.

    2. No, it won't do it for imported records. That would have to be done prior to importing it, or via the import engine.

    There is another possible way of handling it which would make all of this a moot point, but that's a bit more involved. I'll give it a look over the weekend if time permits.

    No prob about the questions. Better to ask than to assume.

    Hi Angel,

    thanks for the response, while I waited for you to reply I had a look at the code as well. I see that you are using a java-script to format the number when it is entered and before it is saved in the database.

    Of course, as you confirmed, it does not do anything to the imported records and it wont affect the already existing numbers.

    I had already thought about using a PHP script to modify the phone numbers already present in the database but I decided against it. I like to keep the numbers in a string format, and I usually get my leads with numbers in string format. Of course, I can format the number before I import them, I tried that, it's easily doable. But for some reason (perhaps as a force of habit), I like the numbers without anything in them.

    So what I really want to do is just the Detail View / List View pages to show the phone numbers in a formatted (333) 555-1212 format. I guess that can be done with a php function such as this one:

    Code:
    <?php
     function CheckUSPhoneNum( $PhoneNumber )
     {
            $PhoneNumber = ereg_replace( "[^0-9]", "", $PhoneNumber ); // Strip out non-numerics    
    
            if( ereg( "^([0-9]{3})([0-9]{3})([0-9]{4})$", $PhoneNumber, $NumberParts ) )                                   
                    return "(" . $NumberParts[1] . ") " . $NumberParts[2] . "-" . $NumberParts[3];
            else
                    return false;
    }
    ?>
    and then pass the phone number through this function before being displayed. I'm just not sure where to make the changes. As the Detail View file is an HTML file, I guess I have to put this in the Detailview.php or is it at some other level that the phone number variable is passed to detailview.html? perhaps for the leads module, in the "lead.php" file? But as I'm not a programmer I don't really know how the data is being passed from where to where....

    Once again, thanks for all the help, it's really appreciated!


    Regards,

    Amit Malhotra

  6. #6
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Displaying Phone Numbers in a specific way

    You are on the right track. That's the basic idea I was thinking of; make the modification after the data is retrieved from the SQL server.

    I took a quick look at the code and it shouldn't be all that difficult. I'll try to get you something later today.
    Regards,

    Angel Magaņa
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  7. #7
    tanhaa is offline Sugar Community Member
    Join Date
    Jul 2006
    Posts
    38

    Default Re: Displaying Phone Numbers in a specific way

    Quote Originally Posted by Angel
    You are on the right track. That's the basic idea I was thinking of; make the modification after the data is retrieved from the SQL server.

    I took a quick look at the code and it shouldn't be all that difficult. I'll try to get you something later today.
    great!! Thanks Angel. In the mean time, I have been looking into javascript to see if I can use javascript to format the phone number before the detail view or list view page loads up. I think PHP function is a better way, but considering I don't know where to parse the value before it's passed on.. at least with javascript I know it will go right on the html page

    Thanks a lot though!! It's really cool that you are spending so much time to help a fella out


    Regards,


    Amit Malhotra

  8. #8
    tanhaa is offline Sugar Community Member
    Join Date
    Jul 2006
    Posts
    38

    Default Re: Displaying Phone Numbers in a specific way

    ok, so I could use this javascript code on the (for example) detailview.html page:

    Code:
    <script type="text/javascript" language="Javascript"> 
    
    function formatUSPhoneNumber(numToFormat){
    areaCode = numToFormat.substring(0,3)
    prefix = numToFormat.substring(3,6)
    suffix = numToFormat.substring(6,10)
    return("(" + areaCode + ") " + prefix + "-" + suffix)
    
    } 
    
    </script>
    then pass the phone number through this function. How do I use the function on the page?

    if I do:

    Code:
    <td  valign="top" class="tabDetailViewDL"><slot>{MOD.LBL_OFFICE_PHONE}</slot></td>
    	<td  valign="top" class="tabDetailViewDF"><slot>document.write(formatUSPhoneNumber('{PHONE_WORK}')) &nbsp;</slot></td>
    what I get is phone number showing up as:

    document.write(formatUSPhoneNumber('{3335551212}') )

    any idea how I can make the phone number pass through this function on the detailview.html page?

    As you can see, I'm really not a programmer..

    TIA
    Amit Malhotra

  9. #9
    tanhaa is offline Sugar Community Member
    Join Date
    Jul 2006
    Posts
    38

    Default Re: Displaying Phone Numbers in a specific way

    ok got it working.

    With the above javascript function, i forgot to call for javascript in the slot, so with this code:

    Code:
    <td  valign="top" class="tabDetailViewDL"><slot>{MOD.LBL_OFFICE_PHONE}</slot></td>
    	<td  valign="top" class="tabDetailViewDF"><slot><script type="text/javascript"> document.write(formatUSPhoneNumber('{PHONE_WORK}'));	</script></slot></td>
    The phone number is displayed exactly the way I want it.


    Thank you so much for all your help Angel. Talking to you pushed me in the right direction for the fix.


    Regards,


    Amit Malhotra

  10. #10
    tanhaa is offline Sugar Community Member
    Join Date
    Jul 2006
    Posts
    38

    Default Re: Displaying Phone Numbers in a specific way

    Maybe I spoke too soon

    although the above mentionned way did work in the "detailview.html" page, it did not work in the "listview.html" page.

    Code:
    <td valign=TOP class="{ROW_COLOR}S1" bgcolor="{BG_COLOR}"  nowrap><slot>{LEAD.PRIMARY_ADDRESS_STATE}</slot></td>
    	<td valign=TOP class="{ROW_COLOR}S1" bgcolor="{BG_COLOR}"  nowrap><slot><script type="text/javascript"> document.write(formatUSPhoneNumber('{LEAD.PHONE_WORK}')); </script></slot></td>
    Any idea? The phone number column shows up blank in the list view area when I do that.

    TIA,

    Amit Malhotra

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •