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)