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

Thread: Get Primary Email Address field in Sugar CRM

  1. #1
    mrhrk is offline Member
    Join Date
    Jul 2009
    Posts
    7

    Thumbs up Get Primary Email Address field in Sugar CRM

    Hi All

    I am using Sugar CRM 5.2.f Community Edition.
    Web server is Apache and the OS is Linux.
    PHP Version 5
    MySQL -Version 5.0.45 and MySQL client version: 5.0.22.

    Currently on the EditView of the Contacts Module i can add multiple email addresses for a Contact. Now only one of these email addresses can be set to the primary email address as the option for this is a radio button.

    What i would like to achieve is when the form is saved, it takes the option which is set in the radio button and sets the saved value to a hidden variable which i can then access in the after save event in the logic hook and do some processing.

    My problem is that the sugar bean only records the email address as email 1, email 2 etc. It does not notify me which is the Primary email address. Thus I require a method to find out the primary email address for this client and possibly place a notifier in the bean telling me this email address is a primary email address and then process this in my logic hook which is fired on the event of "after_save".

    I hope i have clearly outlined my problem, and i would be very grateful if some body could nudge me in the right direction or help me.

    Many Thanks.
    mrhrk

  2. #2
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Get Primary Email Address field in Sugar CRM

    PHP Code:
    require_once 'include/SugarEmailAddress/SugarEmailAddress.php';
    $sea = new SugarEmailAddress;
    $primary $sea->getPrimaryAddress($bean); 
    This should do it.
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  3. #3
    mrhrk is offline Member
    Join Date
    Jul 2009
    Posts
    7

    Thumbs up Re: Get Primary Email Address field in Sugar CRM

    Quote Originally Posted by SugarDev.net View Post
    PHP Code:
    require_once 'include/SugarEmailAddress/SugarEmailAddress.php';
    $sea = new SugarEmailAddress;
    $primary $sea->getPrimaryAddress($bean); 
    This should do it.
    Thanks very much for your help. This works great, however it does not work when i change the primary address to a different email address. It returns the old primary email address which is ofcourse wrong.

    I will show what i mean, suppose i have two email addresses:
    email1@hotmail.com (Set as primary email address)
    email2@hotmail.com

    If i edit the Contact Record and set email2@hotmail.com as the primary email address and save the record, the sugar bean records the primary email address as email1@hotmail.com, which is wrong as it should be email2@hotmail.com.

    It seems the code you gave me runs before the new data has been passed to the bean which would explain why i am not getting the new up to date email address as the primary email address ?

    If you or any one can please help me with this issue, i would be grateful.

    Kind Regards,
    mrhrk

  4. #4
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Get Primary Email Address field in Sugar CRM

    You didn't specify the hook you were using, I suspect it's before_save. Run it in an after_save hook and things should be b-e-autiful.
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  5. #5
    mrhrk is offline Member
    Join Date
    Jul 2009
    Posts
    7

    Default Re: Get Primary Email Address field in Sugar CRM

    Hi

    I did specify in my first post that i was using the "after_save" hook but maybe i didnt state that clearly, sorry for any confusion. However what i dont understand is that why the primary email address is not being updated even when i am running the after_save hook. I am really confused here, any help is appreciated.

    Many Thanks in advance.
    mrhrk.
    Last edited by mrhrk; 2009-08-13 at 08:59 AM.

  6. #6
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Get Primary Email Address field in Sugar CRM

    Ohw I'm sorry, I didn't make out of your post that this hook was also done in after_save.

    Are you sure this hook is fired *before* you start using this hidden variable?
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  7. #7
    mrhrk is offline Member
    Join Date
    Jul 2009
    Posts
    7

    Default Re: Get Primary Email Address field in Sugar CRM

    Hi

    I was unable to place javascript code in the custom code section to do :
    "What i would like to achieve is when the form is saved, it takes the option which is set in the radio button and sets the saved value to a hidden variable which i can then access in the after save event in the logic hook and do some processing." This is my preffered method as i believe it would then get the primary email address every single time (I think ) but i do now know how to implement this.

    So im still confused, as when the record is saved, if i use php my admin to query the table it gets the correct primary email address, but when i query the database through the php script it does not return the correct email address.

    ManyThanks for your lightening quick replies and suggestions.
    Kind Regards

  8. #8
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Get Primary Email Address field in Sugar CRM

    try
    PHP Code:
    $bean->emailAddress->getPrimaryAddress($bean); 
    btw according to SugarEmailAddress, email1 should always contain the primary one.
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  9. #9
    mrhrk is offline Member
    Join Date
    Jul 2009
    Posts
    7

    Default Re: Get Primary Email Address field in Sugar CRM

    Hi

    Thanks for you quick reply again. I have tried the latest code and this does not get the primary email address if you change it as i have explained before.

    I have tried accessing the email1 field in the sugar bean and this is accesible put this does not always contain the primay email address field, So i am back to square 1. Any help is appreciated.

    Many Thanks
    mrhrk

  10. #10
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Get Primary Email Address field in Sugar CRM

    Try recreating the bean in the logic hook which contains your processing?
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

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)

Similar Threads

  1. Replies: 11
    Last Post: 2010-05-19, 08:28 AM
  2. sugar saves spaces in Primary address
    By maus in forum Developer Help
    Replies: 2
    Last Post: 2008-10-22, 08:40 AM
  3. Replies: 0
    Last Post: 2008-06-07, 06:14 PM
  4. Replies: 0
    Last Post: 2008-01-10, 12:32 PM
  5. Replies: 0
    Last Post: 2007-01-04, 09:44 AM

Tags for this Thread

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
  •