Can the bean factory be called in SuiteCRM Process Handler?

Can the bean factory be called in the context of a suitecrm process handler?

(ie for doing field level calculations in the extension framework)I’ve tried:

\BeanFactory::getBean(‘Accounts’, $accountId);

and

use BeanFactory;

BeanFactory::getBean(‘Accounts’, $accountId);

Niether work.

I had to resort to SQL

I think we do not have official supported way to use BeanFactory directly in SuiteCRM v8.x.

Example,

namespace App\Extension\defaultExt\modules\Accounts\Service\Fields;

use App\Process\Entity\Process;
use App\Process\Service\ProcessHandlerInterface;

class AccountCustomCalc implements ProcessHandlerInterface
{
    public const PROCESS_TYPE = 'account-custom-calc';

    public function getProcessType(): string
    {
        return self::PROCESS_TYPE;
    }

    public function run(Process $process)
    {
        $options = $process->getOptions();
        $record  = $options['record']['attributes'] ?? [];

        $someInput  = $record['some_field'] ?? 0;
        $otherInput = $record['other_field'] ?? 0;

        $value = $someInput + $otherInput;

        $process->setStatus('success');
        $process->setMessages([]);
        $process->setData(['value' => $value]);
    }
}

Hey Paul,

Yes they can, see an example in core/backend/Data/LegacyHandler/RecordDeletionHandler.php

It needs to extend LegacyHandler and call init and close.

See also: Add process driven module menu links :: SuiteCRM Documentation

2 Likes