Results 1 to 8 of 8

Thread: Searching by Contact doesn't work

  1. #1
    FishGuts is offline Senior Member
    Join Date
    Apr 2009
    Posts
    26

    Unhappy Searching by Contact doesn't work

    Hi,

    I have a custom module called BuyerJobs. There is a one-to-many relationship between Contacts and BuyerJobs.

    On my BuyerJobs screen, the Basic Search block has a 'Contact' search field, because I want to be able to search BuyerJobs by their related Contacts. But this doesn't work. When I enter a Contact's name (say, Bob Brown), none of Bob Brown's BuyerJobs appears in the results list.

    I've been scratching my head about this for ages. Do you have any solutions?

    I'm using SugarCE 5.2c.

    Thank you

    AG

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Searching by Contact doesn't work

    Hi AG

    Let us know how you added the Contact field into Basic Search and attach into your next post a screen shot of the Search screen.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    FishGuts is offline Senior Member
    Join Date
    Apr 2009
    Posts
    26

    Default Re: Searching by Contact doesn't work

    Hi André,

    Thank you for your swift response. I included the Contact field in the Basic Search by customising the search layout in Studio (after deploying my new BuyerJobs module). As you can see from the attachment, I've labelled the Contact field as 'Buyer'.

    By the way, if you're wondering where the 'Advanced Search' tab disappeared to, well, I got rid of it! hehe

    Thank you,

    AG
    Attached Images Attached Images  

  4. #4
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Searching by Contact doesn't work

    It seems the ListView is generating a wrong sql query.
    Follow the instrucitions into my last post on this thread.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  5. #5
    FishGuts is offline Senior Member
    Join Date
    Apr 2009
    Posts
    26

    Default Re: Searching by Contact doesn't work

    Thanks again André.

    I managed to partially solve the problem by adding the following line to the BuyerJobs module's SearchFields.php file:

    PHP Code:
    'contacts_rej_buyerjobs_name' => array('query_type'=>'default','db_field'=>array('contacts.first_name''contacts.last_name')), 
    Now, if I enter part of a Contact's first name or last name, the Contact's BuyerJobs are successfully shown in the results list. This still does not work if I enter the Contact's full name. I suspect this is because a Contact's full name is not an actual database field - it is merely a concatenation done by Sugar code. Is this correct?

    AG

  6. #6
    ashishmathur is offline Senior Member
    Join Date
    Aug 2008
    Posts
    37

    Default Re: Searching by Contact doesn't work

    This thread helped me too.

    But I have updated field definition slightly to improve search capability:

    Instead of as mentioned in previous post
    PHP Code:
    'contacts_rej_buyerjobs_name' => array('query_type'=>'default','db_field'=>array('contacts.first_name''contacts.last_name')), 
    I have used
    PHP Code:
    'db_field'=>array('TRIM(CONCAT(contacts.first_name," ",last_name))'

  7. #7
    roblaus's Avatar
    roblaus is offline Sugar Community Member
    Join Date
    Dec 2006
    Location
    Vienna / Austria
    Posts
    2,850

    Default Re: Searching by Contact doesn't work

    I am sorry to dig up such an old thread but this problem still exists and drives me crazy. Whenever there is custom module which involves a relationship to contacts the search for contacts doesn't work. The reason is rather simple and can be fixed easily by changing the core files but it is extremely difficult to do this in an upgrade safe manner.

    Sugar searches in this case not as expected for the ID of the contact but as mentioned above for a combination of last_name and first_name. Unfortunately the salutation is subtracted although there is none which results in a query which looks like this "select .... like 'n Doe'" rather than "John Doe".

    The solution above doesn't work because it doesn't take into account that the representation of the name (also in the search field) depends on the user settings - so we may have 'John Doe', 'Doe John' or just 'Doe'.

    I'd appreciate if somebody had an easy solution which I could use...
    __________________________
    Robert Laussegger
    http://www.iscongroup.net

    Bei Fragen: support@iscon.at
    Die deutschen Sprachdateien für SugarCRM und das deutsche Handbuch gibt es hier: http://goo.gl/kPsAz
    Ab sofort auch mit 6.4.2

  8. #8
    roblaus's Avatar
    roblaus is offline Sugar Community Member
    Join Date
    Dec 2006
    Location
    Vienna / Austria
    Posts
    2,850

    Default Re: Searching by Contact doesn't work

    Here is a fix which will work if you set the Name Display Format in your preferences to first last (with or without salutation) or to last only. It will not work with last, first.

    https://github.com/sugarcrm/sugarcrm_dev/pull/87/files

    or differently put: change the file include/SearchForm/SearchForm2.php by commenting out this line
    if(!empty($salutation) && strpos($field_value, $salutation) == 0)

    and adding this line instead
    if(!empty($salutation) && strpos($field_value, $salutation) === true && strpos($field_value, $salutation) == 0)

    around line no 987

    Thanks to Alex from Letrium for helping out here and providing the fix...
    __________________________
    Robert Laussegger
    http://www.iscongroup.net

    Bei Fragen: support@iscon.at
    Die deutschen Sprachdateien für SugarCRM und das deutsche Handbuch gibt es hier: http://goo.gl/kPsAz
    Ab sofort auch mit 6.4.2

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Contact Search Not Searching Description
    By compu523 in forum Developer Help
    Replies: 2
    Last Post: 2009-02-02, 03:11 PM
  2. After upgrading to 5.1, searching invitees don't work
    By arisjr in forum Installation and Upgrade Help
    Replies: 2
    Last Post: 2008-11-11, 11:42 AM
  3. Replies: 2
    Last Post: 2008-10-13, 01:50 PM
  4. Searching Account/Lead/Contact in Google from sugar
    By insideview in forum Developer Help
    Replies: 0
    Last Post: 2007-02-23, 02:16 PM
  5. Contact Searching and Viewing Custom Fields
    By jcborghetti in forum Help
    Replies: 1
    Last Post: 2006-09-06, 12:58 AM

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
  •