Show custom error message on screen

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent
    Senior Member
    • May 2017
    • 178

    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?
  • emillod
    Active Community Member
    • Apr 2017
    • 1416

    #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

    • Vincent
      Senior Member
      • May 2017
      • 178

      #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

      • Vincent
        Senior Member
        • May 2017
        • 178

        #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

        • shalmaxb
          Senior Member
          • Mar 2015
          • 1613

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

          Comment

          • Vincent
            Senior Member
            • May 2017
            • 178

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