Results 1 to 5 of 5

Thread: Custom searches

  1. #1
    DN667 is offline Sugar Community Member
    Join Date
    Jul 2008
    Posts
    36

    Default Custom searches

    Hi all,

    I'm running SugarOS 5.0f. I want to perform a search / select query on the accounts module (for example, in SQL, SELECT * FROM Accounts WHERE (Field1 = A AND Field2 < 5)). Can this be done? If so, how?

    I need these results for a mail merge...

    Best, thanks, Robin

  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: Custom searches

    Hi, Robin

    It is possible to do, you need to follow this steps:

    1. Create the file modules/Accounts/controller.php. In this file you will redefine the bean to be used in the ListView. This bean can be a copy of the Account.php, overriding the method "create_new_list_query", existing in SugarBean.
    2. This method will modify the $ret_array accordingly to your needs.

    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
    DN667 is offline Sugar Community Member
    Join Date
    Jul 2008
    Posts
    36

    Default Re: Custom searches

    Quote Originally Posted by andopes
    Hi, Robin

    It is possible to do, you need to follow this steps:

    1. Create the file modules/Accounts/controller.php. In this file you will redefine the bean to be used in the ListView. This bean can be a copy of the Account.php, overriding the method "create_new_list_query", existing in SugarBean.
    2. This method will modify the $ret_array accordingly to your needs.

    Cheers
    I see.. my guess'd be I'll need to change the actual SQL query to the db? What do I use for keys? Field names?

    How can I access my custom search?

  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: Custom searches

    Hi, DN667

    This is an real example of the content of that function:

    PHP Code:
            $_REQUEST['month_basic'] = isset($_REQUEST['month_basic']) ? $_REQUEST['month_basic'] : date('m');
            
    $_REQUEST['year_basic'] = isset($_REQUEST['year_basic']) ? $_REQUEST['year_basic'] : date('Y');
            
    $delivery_date_start "{$_REQUEST['year_basic']}-{$_REQUEST['month_basic']}-01";
            
    $day_end date('d'mktime(000$_REQUEST['month_basic'] + 10$_REQUEST['year_basic']));
            
    $delivery_date_end "{$_REQUEST['year_basic']}-{$_REQUEST['month_basic']}-" $day_end;
            
    $placement_id_list "";

            if(isset(
    $_REQUEST['mass']) && is_array($_REQUEST['mass']) && count($_REQUEST['mass']) > 0) {
                
    $placement_id_list " AND up2_placements.id IN ('" implode("', '"$_REQUEST['mass']) . "')";
            }

            
    $invoice_no = ($_REQUEST['action_type_basic'] == 'invoiced') ? 'NOT NULL' 'NULL';

            
    $ret_array = array();

            
    $ret_array['select'] = "SELECT invoice_placement_summary.invoice_no AS invoice_id, up2_placements.id, up2_placements.order_number, up2_insertionorders.id AS up2_insertionorders_id, up2_insertionorders.order_number AS io_order_number, invoice_placement_summary.invoice_date AS invoice_date, invoice_placement_summary.id AS invoice_placement_summary_id, up2_placements.quantity, IFNULL(up2_insertionorders.publisher_id, '') AS publisher_id ";

            
    $ret_array['from'] = " FROM invoice_placement_summary INNER JOIN up2_placements ON invoice_placement_summary.placement_number = up2_placements.order_number INNER JOIN up2_insertionorders ON up2_placements.up2_insertionorders_id = up2_insertionorders.id INNER JOIN placements_forecasts ON up2_placements.id = placements_forecasts.placement_guid ";

            
    $ret_array['where'] = " WHERE invoice_placement_summary.invoice = 1 AND invoice_placement_summary.invoice_no IS $invoice_no AND invoice_placement_summary.invoice_start_date >= '$delivery_date_start' AND invoice_placement_summary.invoice_end_date <= '$delivery_date_end' AND up2_placements.deleted=0 AND placements_forecasts.delivery_date BETWEEN '{$delivery_date_start}' AND '{$delivery_date_end}' $placement_id_list";

            
    $ret_array['order_by'] = " GROUP BY up2_placements.id HAVING publisher_id IS NOT NULL ORDER BY up2_placements.name ASC ";

            return 
    $ret_array
    You can access the SearchFields by $_REQUEST or $_POST

    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
    kenshiro is offline Sugar Community Member
    Join Date
    Mar 2007
    Location
    Macerata - ITALY
    Posts
    421

    Default Re: Custom searches

    Quote Originally Posted by DN667
    Hi all,

    I'm running SugarOS 5.0f. I want to perform a search / select query on the accounts module (for example, in SQL, SELECT * FROM Accounts WHERE (Field1 = A AND Field2 < 5)). Can this be done? If so, how?

    I need these results for a mail merge...

    Best, thanks, Robin
    Hi,

    Enhanced Search, a plugin with many useful search options, might come in use.

    It adds, among the others, numeric search oprions to int, decimal and currency search fields (FULL & DEMO version).

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. upgraded to 4.5.1e, received "Metadata for table tracker does not exist"
    By sfgeorge in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2007-09-03, 02:24 PM
  2. Replies: 0
    Last Post: 2006-12-20, 11:39 PM
  3. Asterisk Patch 1.1.0 Crash on logon
    By skyracer in forum Help
    Replies: 6
    Last Post: 2006-07-08, 06:30 AM
  4. Replies: 7
    Last Post: 2006-06-06, 07:56 PM
  5. Custom field searches
    By leejordan in forum Help
    Replies: 2
    Last Post: 2006-02-20, 01:31 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
  •