this.getRouter not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dodom2
    Senior Member
    • Jan 2020
    • 198

    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
  • eymen-elkum
    Active Community Member
    • Nov 2014
    • 472

    #2
    Try this.getRouter instead of this.view.getRouter
    CEO of Eblasoft
    EspoCRM Expert since 2014
    Full Stack Web Developer since 2008
    Creator of Numerous Successful Extensions & Projects​

    Comment

    • dodom2
      Senior Member
      • Jan 2020
      • 198

      #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

      • eymen-elkum
        Active Community Member
        • Nov 2014
        • 472

        #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 of Eblasoft
        EspoCRM Expert since 2014
        Full Stack Web Developer since 2008
        Creator of Numerous Successful Extensions & Projects​

        Comment

        • dodom2
          Senior Member
          • Jan 2020
          • 198

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

          Comment


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