Announcement

Collapse
No announcement yet.

this.getRouter not working

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

  • this.getRouter not working

    Hi All,

    I tried to follow this tutorial https://docs.espocrm.com/development/custom-buttons/
    My problem is I am unable to navigate to next route.
    The following code will not work. I have this error: Cannot read property 'navigate' of undefined. Which in fact means this.view does not exist
    this.view.getRouter().navigate('#SalesOrder/create', {trigger: true});

    Samely the following will not work
    this.getRouter().navigate('#SalesOrder/create', {trigger: true});

    Here is my full code.
    define('custom:views/invoice/create-po-handler', [], function (Dep) {

    return Dep.extend({
    actionCreatePo: function (data, e) {
    //Espo.Ajax.getRequest('Lead/' + this.view.model.id).then(function (response) {
    console.log("actionCreatePo");
    //});
    },

    initCreatePo: function () {
    console.log("eer");
    console.log(this);
    console.log(this.view);
    //this.view.getRouter().navigate('#SalesOrder/create', {trigger: true});
    //this.controlButtonVisibility();
    this.listenTo(
    this.view.model, 'change:status', this.controlButtonVisibility.bind(this)
    );
    },

    controlButtonVisibility: function () {
    console.log("controlButtonVisibility");
    /*if (~['Converted', 'Dead', 'Recycled'].indexOf(this.view.model.get('status'))) {
    this.view.hideHeaderActionItem('someName');
    } else {
    this.view.showHeaderActionItem('someName');
    }*/
    },
    });
    });

    Please can you tell me what am doing wrong here?
    Thanks

  • #2
    Try this.getRouter instead of this.view.getRouter
    CEO & Founder of Eblasoft.
    Professional EspoCRM development & extensions.

    Comment


    • #3
      I have tried both eymen-elkum
      console.log(this.getRouter()); is displaying "undefined".
      Is there a special class from which I should extends for this to work?

      Comment


      • #4
        Ah Yeas, I have just figured it out,

        You have to use this.view.getRouter();

        BUT: not in the initCreatePo, because in initCreatePo the view will not be initiated yet, just move this line to inside the function actionCreatePo: function (data, e)
        CEO & Founder of Eblasoft.
        Professional EspoCRM development & extensions.

        Comment


        • #5
          No chance unfortunately. Having same issue. Both did not work in actionCreatePo on button click.

          Comment


          • espcrm
            espcrm commented
            Editing a comment
            Looking forward to your success so I can start giving it a try too.
        Working...
        X