Announcement

Collapse
No announcement yet.

Formula code to prevent saving changes

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

  • Formula code to prevent saving changes

    Hello,

    is it possible to prevent saving changes in Quote by writing the conditions in formula?

  • #2
    it depends on what field do you want to reset?

    Comment


    • #3
      I have a read only float field C and its value is the result of fields A and B (C = A * B), I want to prevent changes to A or B if A * B is less than 10. Basically I want C to always be more than 10.

      Comment


      • #4
        with formula you can only set the value. For example check the result, and it is less than 10, set 10 or A or B. With formula you can not show the error and stop saving process.
        You can do it with hooks or with validation in the view of this field

        Comment


        • #5
          I have made a hook, however, I can't figure out what kind of line will prevent saving the changes

          I tried using throw new Conflict, however, this allows to change the numbers in the database (I assume) but doesn't change the numbers in the view, so when I refresh I see the changed numbers.

          Is there a way to at least refresh the view automatically when this happens? Or preferably bring the user back to edit mode the way it is done when, for example, a required field is not filled.

          <?php
          namespace Espo\Custom\Hooks\Objektas;
          use Espo\Core\Exceptions\Conflict; use Espo\ORM\Entity; class MinimalusIkainis extends \Espo\Core\Hooks\Base
          {
          public function beforeSave(Entity $entity, array $options = array())
          {
          $ikainis = $entity->get('ikainis1');
          if ($ikainis < 2.45)
          throw new Conflict(json_encode(['Error:' => 'details']));
          }
          }
          Last edited by TitasB; 08-09-2018, 07:48 PM.

          Comment


          • #6
            throw \Error('Invalid ikainis');

            Comment

            Working...
            X