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 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"

No comments: