If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
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.
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
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']));
}
}
Comment