Domanda

I've applied a phone formatting modification to the Contact's phone number. Now, when a user saves a Contact's phone number, it will save in the format of (xxx) xxx-xxxx instead of the default xxxxxxxxxx.

However, I want to do searches that can find records with either of the formats inputted. I modified /custom/modules/Accounts/metadata/SearchFields.php with these changes:

'phone_office' => array(
                'query_type'=>'default',
                'operator' => 'subquery',
                'subquery' => array(
                    'SELECT phone_office FROM accounts WHERE phone_office LIKE  "%"', 
                    'SELECT phone_office FROM accounts WHERE REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( phone_office,  "+",  "" ) ,  "-",  "" ) ,  "(",  "" ) ,  ")",  "" ) ,  " ",  "" ) LIKE  "%"',
                    'OR' =>true   
                    ),
                'db_field'=>array('phone_office'),
                'vname' =>'LBL_PHONE_OFFICE',
        ),

But after these changes, firing up basic or advanced search using this just puts the browser in non-responsive state. Apparently, one can't use an array in 'subquery' because when I set it to only accept one of the select statements, they follow through. Can anyone help me fix this?

È stato utile?

Soluzione 2

Arrgh. Newbie mistake. I needed to replace 'phone_office' with 'id' within the SELECT statement. This should be the syntax:

'phone_office' => array(
            'query_type'=>'default',
            'operator' => 'subquery',
            'subquery' => array(
                'SELECT id FROM accounts WHERE phone_office LIKE  "%"', 
                'SELECT id FROM accounts WHERE REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( phone_office,  "+",  "" ) ,  "-",  "" ) ,  "(",  "" ) ,  ")",  "" ) ,  " ",  "" ) LIKE  "%"',
                'OR' =>true   
                ),
            'db_field'=>array('phone_office'),
            'vname' =>'LBL_PHONE_OFFICE',
    ),

Now it works as it should. I guess I found out today that just because it works on MySQL doesn't necessarily mean it's gonna work in SugarCRM. Thanks for helping me out!

Altri suggerimenti

Try

'phone_office' => array(
            'query_type'=>'default',
            'operator' => 'subquery',
            'subquery' => array(
                'SELECT phone_office FROM accounts WHERE phone_office LIKE ', 
                'SELECT phone_office FROM accounts WHERE REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( phone_office,  "+",  "" ) ,  "-",  "" ) ,  "(",  "" ) ,  ")",  "" ) ,  " ",  "" ) LIKE ',
                'OR' =>true   
                ),
            'db_field'=>array('phone_office'),
            'vname' =>'LBL_PHONE_OFFICE',
    ),

the % is added by sugar. See modules\Employees\metadata\SearchFields.php for field phone

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top