Announcement

Collapse
No announcement yet.

Opportunity Email as PDF

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

  • Opportunity Email as PDF

    I've read all the forum posts on this topic to try to figure it out:
    https://forum.espocrm.com/forum/deve...uestion-newbie
    https://forum.espocrm.com/forum/gene...s-template-pdf

    But I still can't figure it out. I just want to Email a PDF template on the Opportunity entity just like in Quotes "Email PDF".

    I edited "..\client\modules\crm\src\views\opportunity\detai l.js" and added code from Quotes detail.js file:

    PHP Code:
    Espo.define('crm:views/opportunity/detail''views/detail', function (Dep) {

    return 
    Dep.extend({

    setup: function () {
        
    Dep.prototype.setup.call(this);
        
    this.dropdownItemList.push({
            
    name'composeEmail',
            
    label'Email PDF'
        
    });

    },

    actionComposeEmail: function () {
        
    this.createView('pdfTemplate''views/modals/select-template', {
            
    entityTypethis.model.name
        
    }, function (view) {
            
    view.render();
            
    this.listenToOnce(view'select', function (model) {
                
    this.notify('Loading...');
                
    this.ajaxPostRequest('Opportunity/action/getAttributesForEmail', {
                    
    opportunityIdthis.model.id,
                    
    templateIdmodel.id
                
    }).done(function (attributes) {
                    var 
    viewName this.getMetadata().get('clientDefs.Email.modalViews.compose') || 'views/modals/compose-email';
                    
    this.createView('composeEmail'viewName, {
                        
    attributesattributes,
                        
    keepAttachmentsOnSelectTemplatetrue
                    
    }, function (view) {
                        
    view.render();
                        
    this.notify(false);
                    }, 
    this);
                }.
    bind(this));
            }, 
    this);
        }, 
    this);
    },
    ... 

    With the above code inserted the Opportunity detail page doesn't display the data.. it just gets stuck at "Loading..".

    And I don't know where to put the "getAttributesForEmail" function:
    "..\crm\application\Espo\Modules\Crm\Services\ Oppo rtunity.php" or "..\crm\application\Espo\Modules\Advanced\Serv ices \Opportunity.php"

    Please any support is appreciated here..
    Last edited by ashballan; 06-09-2018, 03:10 PM.

  • #2
    Request is directed to the entity Controller first. After Controller could call service methods.
    Check application/Espo/Modules/Advanced/Controllers/Quote.php

    Comment


    • #3
      OK, I added the function to the Opportunity controller but still when I enable the "Espo.define.." code above when loading the detail of an Opportunity the system gets stuck at "Loading..." and the record isn't displayed. It's the same code as in Quote so I don't know what the issue is please.

      Comment


      • #4
        Press F12 button. You have js error

        Comment


        • #5
          Cannot read property 'push' of undefined: this.dropdownItemList.push({name: 'composeEmail', label: 'Email PDF'});

          In the "..\client\modules\crm\src\views\opportunity\d etai l.js" file. How do I fix this please?

          BTW, the user in this thread faced the same issue with no solution: https://forum.espocrm.com/forum/gene...s-template-pdf
          Last edited by ashballan; 06-11-2018, 03:14 PM.

          Comment


          • #6
            try this.menu.buttons.push instead of this.dropdownItemList.push

            Comment


            • #7
              No more stuck "Loading.." but I don't get an "Email PDF" button in the menu.. any ideas please?

              Comment


              • #8
                Clear Local Cache, refresh the page and open browser console. What is the error and it what source row?

                Comment


                • #9
                  Yes, I tried all that but still the "Email PDF" button is not appearing in the menu. There are no errors at all..

                  Comment


                  • #10
                    I promissed my users to implement this so would really appreciate some help here.

                    Comment


                    • #11
                      You need this button on detail view (follow button area) or record detail view (edit / remove button area)?

                      example for first variant https://github.com/espocrm/espocrm/b.../detail.js#L59
                      example for second variant https://github.com/espocrm/espocrm/b...detail.js#L242

                      Comment


                      • #12
                        Hi Tanya, I want the button, exactly like it's done in Quotes, in the edit/remove button area. And as before, I added this code in \client\modules\crm\src\views\opportunity\detail.j s:

                        setup: function () {
                        Dep.prototype.setup.call(this);
                        this.dropdownItemList.push({
                        name: 'composeEmail',
                        label: 'Email PDF'
                        });
                        },

                        But, when loading an Opportunity the page crashes at Loading... with an error: "Uncaught TypeError: Cannot read property 'push' of undefined at child.setup..".

                        What am I doing wrong? Why can't it recognize this.dropdownItemList.push?
                        Last edited by ashballan; 06-19-2018, 12:24 PM.

                        Comment


                        • #13
                          you want to make changes on detail view in "views", but you need detail view in "recordView".... it's important



                          your view has to be defined in \client\custom\src\views\opportunity\record\detail .js
                          don't forget to set this view in custom clientDefs

                          Comment

                          Working...
                          X