Show custom error message on screen

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • shalmaxb
    commented on 's reply
    Thank you very much

  • Vincent
    replied
    Hi
    I have created a TEST entity. In the system generated custom\Espo\Custom\Repositories\TEST.php, i added a beforeSave function in the file. Code is as follows:

    <?php

    namespace Espo\Custom\Repositories;
    use Espo\Core\ORM\Entity;
    use Espo\Core\Exceptions\Error;
    use Espo\Core\Exceptions\Conflict;

    class TEST extends \Espo\Core\Templates\Repositories\Base
    {
    protected function beforeSave(Entity $entity, array $options = [])
    {
    parent::beforeSave($entity, $options);
    throw new Error('it is a custom error');
    }

    }
    }

    An error message 'it is a custom error' is shown on the screen when i save the record of TEST entity

    Leave a comment:


  • shalmaxb
    replied
    Hi, would you be so kind to post your solution here?

    Leave a comment:


  • Vincent
    replied
    emillod, thank you.
    I have update the custom\Espo\Custom\Repositories\MyEntity.php following your suggestion. It can now show the custom error message on screen

    Leave a comment:


  • Vincent
    replied
    Hello
    I set the before save custom script using Web UI (Entity > My Entity> Formula). What is the file, i should put "use Espo\Core\Exceptions\BadRequest;" and "
    throw new BadRequest('error');"? Thanks.

    Leave a comment:


  • emillod
    replied
    Hello.
    Use "use Espo\Core\Exceptions\BadRequest;" in header and in script use "
    throw new BadRequest('error'); " sam thing with Error or NotFound.

    Everything you can find in EspoCRM repo.

    Leave a comment:


  • Vincent
    started a topic Show custom error message on screen

    Show custom error message on screen

    Is there a way to show custom error message on screen when the validation in the before save script not passed?
Working...