Friday, July 23, 2010

sugarcrm logic hook problem

I created an after_save logic hook for Lead. My SugarCRM is version 5.5.2 and the function is quite simple:
function runMeAfterSave(SugarBean $bean, $event, $arguments)
{
if ($bean->first_name == 'someone') {
//do some tasks
}
}

The function works very well on my localhost. When i put it on another server, however, it doesn't work at all. So, i var_dump($bean->first_name), and it turns out to be NULL all the time, no matter what value i enter into first name field. I var_dump some other fields and get NULL as well. The server SugarCRM version is 5.5.3. I can't find any reason why it can't work.

Finally, i try var_dump($bean->id). This time i'm lucky! I can get its ID! So i add one line in my code: $bean->retrieve($bean->id) and everything works fine now.

Later I found a thread on SugarCRM forum regarding this issue http://panther.sugarcrm.com/forums/showthread.php?t=44872. It says "The problem was that after_save, the bean discards all the new field info. So we needed to use $bean->retrieve($bean->id); to get it back"

Thursday, July 8, 2010

sugarcrm warning message

I created a new module. When i save a new entry, sugarcrm will show this message:
Warning: preg_match() expects parameter 2 to be string, array given in /var/www/crm/include/utils.php on line 1715

Call Stack
# Time Memory Function Location
1 0.0000 72612 {main}( ) ../index.php:0
2 0.0001 73516 require_once( '/var/www/crm/include/entryPoint.php' ) ../index.php:38
3 0.0019 214344 clean_incoming_data( ) ../entryPoint.php:124
4 0.0067 235068 clean_string( ) ../utils.php:1797
5 0.0068 235120 preg_match ( )
../utils.php:1715

So I traced the code back to line 1797 in utils.php, and found this code "if (isset($_REQUEST['language'])) clean_string($_REQUEST['language']);".

Actually in this new module, i created a field called 'language' and it is MultiSelect type, which is an array. After i change the field name, this warning message disappeared.