Announcement

Collapse
No announcement yet.

Removing record based on value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Removing record based on value

    Is there a preferred method to disable removing a record based on some value of that record ?

    For example : you cannot delete an Account if the country is UA.

    Same applies to disable "edit" (set record to readonly)

    example


  • #2
    anyone? It would be very nice to have this in the workflow:

    Trigger : before delete record
    Criteria : country = UA
    Action : show message : You cannot delete Account from UA
    Action : disallow deletion

    Comment


    • #3
      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


      • #4
        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");
                }
            }
        }
        More about hooks you can find here: https://docs.espocrm.com/development/hooks.

        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.

        Comment


        • #5
          yep that might be OK for now, no UI for this is not a problem either. Thank you.

          Comment

          Working...
          X