How to get data via BeanFactory in custom file ?

I try to use BeanFactory to get data in Case module but nothing return.

$bean = BeanFactory::getBean('Cases');
$bean->retrieve('id');
$name = $bean->name;
echo $name;

Ref:

http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.5/API/Classes/BeanFactory/

How to use BeanFactory in custom file ?

SugarCRM Enterprise, Version 7.6.1.0 (Build 1163)

Thanks,

M

---------------------------- More ------------------------------

I got this error when put ini_set('display_errors', 1); into my code.

Fatal error: Class 'BeanFactory' not found in /sugarcrm/addon/reminder/testBean.php on line 26

Parents Reply
  • Hi Autchara,

    Typically when custom code is getting executed within the Sugar infrastructure, the BeanFactory class is autoloaded. Since the PHP error you are receiving is that the class was not found, you can manually require it in your custom code. The BeanFactory class is located in ./data/BeanFactory.php and can be included for use in your code by adding the require_once line at the top of your custom file:

    <?php
    require_once('data/BeanFactory.php');
    

    -Mark

Children