Issue with adding Process Handler - "Internal server error"

I have tried to follow this guide on creating a Process Handler. I have a custom module “eks_activity” where there are two fields kilometerstand_von_c and kilometerstand_bis_c . Based on their values I would like to calculate the value in gesamtkilometer_c.

This is my detailviewdefs.php

array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'kilometerstand_von_c',
            'label' => 'LBL_KILOMETERSTAND_VON',
          ),
          1 => 
          array (
            'name' => 'kilometerstand_bis_c',
            'label' => 'LBL_KILOMETERSTAND_BIS',
          ),
        ),
        1 => 
        array (
            0 => [
                'name' => 'gesamtkilometer_c',
                'logic' => [
                    'calculate_km' => [
                        'key' => 'updateValueBackend',
                        'modes' => ['edit', 'create'],
                        'params' => [
                            'fieldDependencies' => [
                                'kilometerstand_von_c',
                                'kilometerstand_bis_c',
                            ],
                            'process' => 'calculate_km',
                            'activeOnFields' => [
                                'kilometerstand_von_c' => 
                                ['operator' => 'not-empty' ],
                                'kilometerstand_bis_c' => [
                                    ['operator' => 'not-empty' ]
                                ]
                            ]
                        ]
                    ],
                ]
            ],
        ),

When I enter values a Graphql request is being sent:


but I get the following as a response

{
    "errors": [
        {
            "message": "Internal server error",
            "extensions": {
                "category": "internal"
            },
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "createProcess"
            ]
        }
    ],
    "data": {
        "createProcess": null
    }
}

This is my Backend handling code located in extensions/defaultExt/modules/eks_activity/Service/Fields/calculate_km.php:

<?php

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

use ApiPlatform\Core\Exception\InvalidArgumentException;
use App\Process\Entity\Process;
use App\Process\Service\ProcessHandlerInterface;

class calculate_km implements ProcessHandlerInterface
{
    protected const MSG_OPTIONS_NOT_FOUND = 'Process options are not defined';
    protected const MSG_INVALID_TYPE = 'Invalid type';
    public const PROCESS_TYPE = 'calculate_km';

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

    public function requiredAuthRole(): string
    {
        return 'ROLE_USER';
    }

    public function getRequiredACLs(Process $process): array
{
    return [];
}

    public function configure(Process $process): void
    {
        $process->setId(self::PROCESS_TYPE);
        $process->setAsync(false);
    }

    public function validate(Process $process): void
    {
    }

    public function run(Process $process)
    {
        $options = $process->getOptions();

        $kilometerstand_von = (float)($options['record']['attributes']['kilometerstand_von_c'] ?? 0);
        $kilometerstand_bis = (float)($options['record']['attributes']['kilometerstand_bis_c'] ?? 0);
        $difference = 50;
        #$kilometerstand_bis - $kilometerstand_von;

        $responseData = [
            'value' => $difference
        ];

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

I am using SuiteCrm 8.4.0 with PHP 8.2.7 and Angular:

Angular CLI: 12.2.18
Node: 14.15.1
Package Manager: npm 6.14.8
OS: linux x64

Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1202.18 (cli-only)
@angular-devkit/core         12.2.18 (cli-only)
@angular-devkit/schematics   12.2.18 (cli-only)
@schematics/angular          12.2.18 (cli-only)

I have also come across this post detailing a similar problem but adapting the solution hasn’t worked. Based on the code I believe that suitecrm somehow doesn’t find my processhandler

Hey @dwaltsch,

I’ve been looking through these myself.

In the example they always use psr compliant classes, I’m not sure if that is the cause, but probably worth the try. You would need name your class CalculateKm and the file should also be CalculateKm.php.

Also, did you remember to run php bin/console cache:clear after adding the class?

According to the following thready you can get some more debug information if set APP_ENV on .env.local to qa. Then on the response you get the error there will be a stacktrace and more info.

1 Like

Thanks for the reply seems like my initial code had a bug in it which prevent it from working. After modifying the code, I forgot to clean the cache again, so it still used the broken code. Thanks for the debugging suggestion, I’ll look into it.

I also advise keeping an eye on basic Symfony documentation since the entire class override process is based on that. In Symfony these are called services.

There is also a useful Symfony console command I can’t check right now but from memory I think it is

bin/console container:debug name_of_your_class

This way you can make sure that symfony is finding your class and using it instead of the original class (for overrides), or adding it to the loaded classes (for extensions).

2 Likes

Thx for the suggestion it is

bin/console debug:container name_of_class
1 Like