Announcement

Collapse
No announcement yet.

Show custom error message on screen

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

  • 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?

  • #2
    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.

    Comment


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

      Comment


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

        Comment


        • #5
          Hi, would you be so kind to post your solution here?

          Comment


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

            Comment


            • shalmaxb
              shalmaxb commented
              Editing a comment
              Thank you very much
          Working...
          X