Announcement
Collapse
No announcement yet.
Removing record based on value
Collapse
X
-
Bump
I still have the question that I would like to have a similar thing like the dynamic logic as is possible at field level
Dynamic Logic
Conditions making record visible
Conditions making record read-only
Conditions making record invalid
Conditions making deletion of record not possible
Last edited by rinorway; 09-05-2024, 08:09 AM.
Comment
-
Hi rinorway,
In this case, a custom beforeRemove hook will help you.
Example (this is a working version, which may not be entirely correct, so the community forum correction is welcome):
{ESPO_DIR}/custom/Espo/Custom/Hooks/Account/PreventDelete.php
Code:<?php namespace Espo\Custom\Hooks\Account; use Espo\Core\Hook\Hook\BeforeRemove; use Espo\ORM\Entity; use Espo\ORM\Repository\Option\RemoveOptions; use Espo\Core\Exceptions\Error; class PreventDelete implements BeforeRemove { public static int $order = 5; public function beforeRemove(Entity $entity, RemoveOptions $options): void { // Check if the billing address country is set to UA if ($entity->get('billingAddressCountry') === 'UA') { // Throw an error to prevent deletion throw new Error("You cannot delete Account from UA"); } } }
And to prohibit editing, just use the formula script in the Administration > Entity Manager > Account > Formula > API Before-Save Script: https://docs.espocrm.com/administrat...access-control
Users simply won't be able to save the record and will receive an error message.Last edited by lazovic; 09-06-2024, 03:35 PM.
- Likes 1
Comment
Comment