I need to do some decryptions and calculations when I retrieive fields in report, how can I add the contact fields to logic hook in Reports logic hook? How do I retrieve it in after_retrieve hook? I am doing some encryption on the field when I save and retrieve contact fields.
TIA.
Hi,
In SuiteCRM, logic hooks typically work for standard modules and custom modules, but they do not apply directly to AOR (Advanced Open Reports) reports. AOR reports generate their data dynamically based on queries and do not trigger the same save or delete events as standard modules.
You need to create a custom report in which you can directly query the data from the database and decrypt any field you want.
1 Like
Hello Asif Ali,
what kind encryptions do you have to do?
As for the calculation, as Rolustech wrote, usually you’d do this beforehand in workflows, logic hook, integrations, … on record updates and store your results in “analytical fields”.
Those fields are not for data entry, but mostly calculate KPI and similar results.
Depending on what you want to do with reports and live calculations, you can use external BI software, then you don’t have to add analytical fields inside your CRM and keep the records clean.
Check out my video on an idea / example:
1 Like
I have a CRM which required AES encryption for a few fields, which I implemeneted in Logic hook while saving and viewing. Now it returns encrypted hashed data when I pull it in reports.
I assume you’d need to build custom code reports - probably:
- SQL queries to retrieve your data
- Decrypt your data
- Generate your required tables / charts
and that usually live.
I’m curious: How do you display encrypted data in list / detail view?
Custom fields with a live decrypt logic?
1 Like
public function beforeSave($bean, $event, $arguments)
{
// Encrypt specific fields
$bean->nic_no_c = Encryption::encrypt($bean->nic_no_c);
$bean->passport_number_c = Encryption::encrypt($bean->passport_number_c);
$bean->phone_work = Encryption::encrypt($bean->phone_work);
$bean->phone_mobile = Encryption::encrypt($bean->phone_mobile);
$bean->email1 = Encryption::encrypt($bean->email1);
$bean->primary_address_1_c = Encryption::encrypt($bean->primary_address_1_c);
$bean->town_c = Encryption::encrypt($bean->town_c);
$bean->district_c = Encryption::encrypt($bean->district_c);
// $bean->birthday_c = $bean->birthdate;
// $bean->postcode_c = $bean->primary_address_postalcode;
// $bean->primary_address_postalcode = Encryption::encrypt($bean->primary_address_postalcode);
// $bean->birthdate = Encryption::encrypt($bean->birthdate);
}
public function afterRetrieve($bean, $event, $arguments)
{
// Decrypt specific fields
$bean->nic_no_c = Encryption::decrypt($bean->nic_no_c);
$bean->passport_number_c = Encryption::decrypt($bean->passport_number_c);
$bean->phone_work = Encryption::decrypt($bean->phone_work);
$bean->phone_mobile = Encryption::decrypt($bean->phone_mobile);
$bean->email1 = Encryption::decrypt($bean->email1);
$bean->primary_address_1_c = Encryption::decrypt($bean->primary_address_1_c);
$bean->town_c = Encryption::decrypt($bean->town_c);
$bean->district_c = Encryption::decrypt($bean->district_c);
$bean->primary_address_postalcode = Encryption::decrypt($bean->primary_address_postalcode);
// Decrypt the birthdate and ensure it is a valid date format
$decryptedBirthdate = Encryption::decrypt($bean->birthdate);
if (!empty($decryptedBirthdate)) {
// Parse the date and format it to YYYY-MM-DD if necessary
$formattedDate = date('Y-m-d', strtotime($decryptedBirthdate));
$bean->birthdate = $formattedDate;
} else {
$bean->birthdate = ''; // Handle case when no birthdate is available
}
}
This is my Custom Hook to encrypt on save and to decrypt on view.
I see, nice one.
That implies, that the decrypted info is never stored in the DB as it seems.
Therefore, you won’t have it available for reports and maybe some other standard functionality (which works off the DB and circumvents the bean data retrieval).
Yeah I have created a custom view page to give a form and an entry point to generate the report so the form does the ajax to that entry point and returns the csv. Does the job.