Announcement

Collapse
No announcement yet.

Note on Case beforeSave hook usage

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

  • Note on Case beforeSave hook usage

    Dear support,


    There is a need to call custom function before saving a "Note" on "Case" and bypass it's plain text body to that function as a parameter.

    As per documentation:


    we created an extension:
    .../EspoCRM-5.1.2/custom/Espo/Custom/Hooks/Note/TelMsg.php
    With this body:

    namespace Espo\Custom\Hooks\Note;

    use Espo\ORM\Entity;

    class TelMsg extends \Espo\Core\Hooks\Base
    {
    public function beforeSave(Entity $entity, array $options = array())
    {
    file_put_contents("test.dump", "");
    }
    }

    however test.dump file has not been created.

    Can you kindly clarify:
    1) what are we doing wrong?
    2) what is execution folder in this case?
    3) how to get data from $entity?:
    a) new note body
    b) parent case object (to be able to operate it's fields as well)

  • #2
    hi,
    did you Clear the Cache?
    data/cache/application/hooks.php - is your hook in Note list?
    does your hook file starts with <?php ?

    Comment


    • #3
      Originally posted by tanya View Post
      hi,
      did you Clear the Cache?
      data/cache/application/hooks.php - is your hook in Note list?
      does your hook file starts with <?php ?
      Hi Tanya

      1) Yes - cache has been cleared through the web interface

      2) data/cache/application/hooks.php - does not contain our hook

      3) Full listing of /EspoCRM-5.1.2/custom/Espo/Custom/Hooks/Note/TelMsg.php:

      <?php
      namespace Espo\Custom\Hooks\Note;

      use Espo\ORM\Entity;

      class TelMsg extends \Espo\Core\Hooks\Base
      {
      public function beforeSave(Entity $entity, array $options = array())
      {
      file_put_contents("test.dump", "");
      }
      }
      ?>

      Comment


      • #4
        check if this file is readable for server user, because I've created this hook with your path and file content and after clearing the cache data/cache/application/hooks.php - does contain your hook

        Comment


        • #5
          Originally posted by tanya View Post
          check if this file is readable for server user, because I've created this hook with your path and file content and after clearing the cache data/cache/application/hooks.php - does contain your hook
          Thank you!
          We have set 755 permissions and cleared cache again through /espo/EspoCRM-5.1.2/#clearCache.

          However it seems that
          /EspoCRM-5.1.2/data/cache/application/hooks.php
          has not been changed since installation

          Any ideas?

          Comment


          • #6
            Now after performing Rebuild and Clear cache through admin panel we are no longer seing this file:
            data/cache/application/hooks.php (https://pasteboard.co/HigtXt1.png)

            How can we fix that?

            Comment


            • #7
              Create any record and check it again.

              Comment


              • #8
                Originally posted by tanya View Post
                Create any record and check it again.
                Many thanks, it works!

                Comment


                • #9
                  Hello!


                  We are trying to deploy existing and working functionality on another server instance however we are facing this issue:
                  Clear cache does not seem to update anything.


                  Can you kindly advice?
                  - yes hooks file does not have our hook reference
                  - yes permissions to the hook are set to 755 and the owner is a propoper web user
                  - yes we tried to create a new case and add comments after clearing cache

                  Or suggest another way to clear cache (for instance clear some catalogs, set some variable or so...).


                  Many thanks

                  Comment


                  • #10
                    From https://www.espocrm.com/documentatio.../installation/

                    Check permission for data folder. It should be 775. Also make sure that you have the correct owner and group.

                    Comment


                    • #11
                      Thank you - somehow that third party managed to clear cache (probably our user did not sufficient privileges in EspoCRM) - issue has been resolved.

                      Comment

                      Working...
                      X