I am a freelance Linux technical service provider, and I am currently reconsidering my CRM system choices. As a regular individual user and technical professional, I know I need to customize my CRM settings. I have hidden most of the core modules, keeping only a few tables that seem potentially useful, and have started making custom modifications to some table constraints and fields. Now, I need to define a field and use a program to automatically generate a unique identifier for the contact and account tables to identify customers. I believe this is a common and reasonable requirement. Therefore, with the help of AI (as a technical professional, I admit that the help provided by AI is almost useless, but due to its powerful retrieval capabilities, it can often complete some simple functions, which can then be better implemented with human intervention. Unfortunately, powerful software like SuiteCRM lacks clear documentation; it doesn’t even have complete and clear interface definitions),
I wrote the following code:
<?php
namespace App\Extension\defaultExt\backend\handler;
use App\Data\Entity\Record;
use App\FieldDefinitions\Entity\FieldDefinition;
use App\Data\Service\Record\RecordSaveHandlers\RecordSaveHandlerInterface;
class UniqueCodeRecordSaveHandler implements RecordSaveHandlerInterface {
public function run(?Record $previousVersion, Record $inputRecord, ?Record $savedRecord, FieldDefinition $fieldDefinition): void {
throw new \Exception("Bingo! 处理器确实被触发了");
$currentCode = $inputRecord->getAttribute('unique_code_c');
$GLOBALS['log']->info("into");
if (!empty($currentCode)) {
return;
}
$n8n_url = 'http://192.168.4.20/webhook/StreamCounter?type=SuiteCRM-CID';
$ch = curl_init($n8n_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200 && is_numeric(trim($response))) {
$counter = (int)trim($response);
$final_code = date('YmdHis') . rand(1000, 9999) . str_pad($counter, 4, '0', STR_PAD_LEFT);
$inputRecord->setAttribute('unique_code_c', $final_code);
}
}
public function getOrder(): int {
return 10;
}
public function getKey(): string {
return 'unique_code_generator_handler';
}
public function getModule(): string {
return 'contacts';
}
public function getModes(): array {
return ['create', 'edit'];
}
}
?>
Typically, I would expect him to at least be able to access my n8n webhook counter interface and create a unique identification code based on a 4-bit year-reset counter value combined with a random code and timestamp. However, he was completely unable to execute this successfully, and SuiteCRM detected a problem with the saving process, as shown in the image.
Are there any official developers or community members who can help me, a new user, better understand and use SuiteCRM?
