Case close button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paulina
    Member
    • Feb 2022
    • 41

    Case close button

    Hello,
    Would be nice to have Case "Close" button next to "Follow" button which would close a Case. Similar to Task entity where is the "Complete" button.

    Click image for larger version

Name:	image.png
Views:	402
Size:	50.1 KB
ID:	96764
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    hey Paulina

    You can achieve this easily on your instance, follow the steps below to achieve same thing on case.

    1 - Create a file Case.json (if not exist) under custom\Espo\Custom\Resources\metadata\clientDefs\C ase.json and paste the code below (create all folders if they don't exist)

    PHP Code:
    {
        "views": {
            "detail": "custom:views/case/detail"
        },
        "menu": {
            "detail": {
                "buttons": [
                    {
                        "label": "Close",
                        "name": "setClosed",
                        "action": "setClosed",
                        "iconHtml": "<span class="fas fa-check fa-sm"></span>",
                        "acl": "edit"
                    }
                ]
            }
        }
    }

    2 - Create a record view detail.js (if not exist) under client\custom\src\views\case\detail.js and paste the code below (create all folders if they don't exist)
    PHP Code:
    define('custom:views/case/detail', ['views/detail'], function (Dep) {
    
        return Dep.extend({
    
            setup: function () {
                Dep.prototype.setup.call(this);
    
                this.controlCloseButton();
                this.listenTo(this.model, 'sync', () => this.controlCloseButton());
            },
    
            controlCloseButton: function () {
                let status = this.model.get('status');
    
                if (['Closed'].includes(status)) {
                    this.hideHeaderActionItem('setClosed');
                }
            },
    
            actionSetClosed: function () {
                this.model
                    .save({status: 'Closed'}, {patch: true})
                    .then(() => {
                        Espo.Ui.success(this.translate('Saved'));
    
                        this.hideHeaderActionItem('setClosed');
                    });
            },
        });
    });

    Once done, clear the cache and rebuild the system and you will have the new close button on the case.

    Hope this helps
    Rabii
    Web Dev

    Comment


    • rabii
      rabii commented
      Editing a comment
      when copying from here the forum the code zill not be cleaned you have to review code to remove any extra caracter.

    • ChrisSka83
      ChrisSka83 commented
      Editing a comment
      I don't think you understood what I meant.
      It was about the double quotation marks
      "fas fa-check fa-sm"

      With this I always got an error 500

      Only when I changed them to single quotes, no more error came.
      'fas fa-check fa-sm'

    • rabii
      rabii commented
      Editing a comment
      i see sorry didn't get it. yeah that should be single quote or escape with double quote. thanks
      Last edited by rabii; 03-25-2024, 12:57 AM.
  • victor
    Active Community Member
    • Aug 2022
    • 728

    #3
    You can also create a button by creating a Workflow with Trigger Type Manual and Element Type Button. In Actions, you need to specify the required action:

    Click image for larger version  Name:	2.png Views:	21 Size:	26.6 KB ID:	96773
    Last edited by victor; 08-24-2023, 07:48 AM.

    Comment

    • macistda
      Member
      • Jul 2022
      • 76

      #4
      Paulina

      Advantage of that kind of Button by rabii, it is at the same Place and is able to change it's letters and colours etc and send an "Update" to e.g. Status-Fields.
      The "easy" way from victor is a very well way, too, if you don't have a bit of "programming" skills.
      So it is a question of skills and design, if you want to do more than one button. Personally I use both variants, depending on what that Button should do.

      I was asked same way here: https://forum.espocrm.com/forum/gene...rmula-question

      Both answers from rabii's as well as victor's are correct

      Comment

      • yuri
        Member
        • Mar 2014
        • 8448

        #5
        Methods which avoid extending are always better. In the future, we may create a separate view class for Case. Our functionality won't work if the custom view extends 'views/detail'. Hence, such methods are not fully upgrade safe.

        The view setup handler or workflow are better options.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment


        • rabii
          rabii commented
          Editing a comment
          you are right, i assume this only applies to entities from crm module hence extending should be done on the basis of existing views on the crm module. reason why extended 'views/detail' is simply because there is no current detail view for Case. will it be possible to provide a fallback view as default when extending ?
      • Paulina
        Member
        • Feb 2022
        • 41

        #6
        Thanks for your suggestions. I will definitely use one

        Comment

        • ChrisSka83
          Senior Member
          • Apr 2023
          • 197

          #7
          Hello everyone,
          I need a little food for thought for the following code:

          PHP Code:
          controlCloseButton: function () {
                      let status = this.model.get('status');
          
                      if (['Closed'].includes(status)) {
                          this.hideHeaderActionItem('setClosed');
                      }
                  },
          I would like to insert an if not query.
          Unfortunately, I can't get very far with a != here.
          Does anyone have an idea of the best way to insert it?​

          Comment


          • rabii
            rabii commented
            Editing a comment
            what do you mean ?
        • rabii
          Active Community Member
          • Jun 2016
          • 1250

          #8
          You can just use

          PHP Code:
          if (!['Closed'].includes(status)) {
              this.showHeaderActionItem('setClosed');
          } 
          
          Rabii
          Web Dev

          Comment


          • ChrisSka83
            ChrisSka83 commented
            Editing a comment
            I had already tried that.
            But it only works halfway.
            If the status is not Closed, the button is not displayed.
            -> Correct so far.

            But if the status is "Closed", I still don't get the button. It remains hidden.

            and yes, cache cleared and rebuild triggered.
            I also use the command via the console:
            command.php update-app-timestamp
        • ChrisSka83
          Senior Member
          • Apr 2023
          • 197

          #9
          Damn, I stand corrected.
          I found the mistake.
          I wrote the name of my status differently than in the code. Then it can't work at all.
          --> Closed was only an example here, my name is completely different.

          But I have changed your code.
          I'll hide the button with your code:
          PHP Code:
          if (!['abholfertig'].includes(status)) {
                          this.hideHeaderActionItem('setClosed');
                      }

          Comment


          • rabii
            rabii commented
            Editing a comment
            it happens
        • yuri
          Member
          • Mar 2014
          • 8448

          #10
          JFI. It's possible to add such buttons with Manual Workflows from Advanced Pack.
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment


          • ChrisSka83
            ChrisSka83 commented
            Editing a comment
            Hy @yuri,
            I really appreciate your work and find your CRM really mega.
            But to add a button, 395 $ is really too much for me, because I don't need the other functions.

            I also think it's better to get to know more of the background in order to understand the CRM better.

          • yuri
            yuri commented
            Editing a comment
            Just letting know for those who already uses Advanced Pack.
        • yuri
          Member
          • Mar 2014
          • 8448

          #11
          I recommend utilizing a handler instead of creating a custom view. Extending views should be a last resort.

          We have this documented: https://docs.espocrm.com/development/custom-buttons/
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • yuri
            Member
            • Mar 2014
            • 8448

            #12
            Back to the topic. We have already the "Close" action in the menu.

            Click image for larger version

Name:	image.png
Views:	138
Size:	14.8 KB
ID:	104159
            If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

            Comment

            • ChrisSka83
              Senior Member
              • Apr 2023
              • 197

              #13
              I don't just use the button to close.
              I have several buttons in several separate entities that execute several commands in different ways.​

              Comment

              • yuri
                Member
                • Mar 2014
                • 8448

                #14
                It doesn't require using custom views. Custom views are not recommended approach. Note that the topic is already hijacked, I answered to the initial post. It's the Feature Request category after all.
                If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

                Comment

                • yuri
                  Member
                  • Mar 2014
                  • 8448

                  #15
                  See the updated example for v8.1: https://github.com/espocrm/documenta...ist-edit-views. With new functions it's much easier now.
                  If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

                  Comment

                  Working...